|
1 | 1 | #![cfg_attr(feature = "fail-on-warnings", deny(warnings))] |
2 | 2 | #![forbid(unsafe_code)] |
3 | 3 | extern crate git2; |
| 4 | +#[macro_use] |
| 5 | +extern crate structopt; |
4 | 6 |
|
5 | 7 | use git2::{Commit, Repository}; |
6 | 8 | use std::cmp::PartialEq; |
7 | 9 | use std::collections::HashMap; |
8 | 10 | use std::env; |
| 11 | +use std::path::PathBuf; |
9 | 12 | use std::error::Error; |
| 13 | +use structopt::clap::AppSettings; |
| 14 | +use structopt::StructOpt; |
10 | 15 |
|
11 | 16 | static CURSES: &str = include_str!("words.txt"); |
12 | 17 |
|
| 18 | +#[derive(StructOpt, Debug)] |
| 19 | +#[structopt( |
| 20 | + name = "git anger-management", |
| 21 | + about = "Ever wondered how angry your commits are? Look no further...", |
| 22 | + raw(global_settings = "&[AppSettings::ColoredHelp]") |
| 23 | +)] |
| 24 | +struct Cli { |
| 25 | + #[structopt(name = "directory", help = "Directory to parse commits", parse(from_os_str))] |
| 26 | + directory: Option<PathBuf>, |
| 27 | +} |
| 28 | + |
13 | 29 | #[derive(Debug, Eq)] |
14 | 30 | struct Author { |
15 | 31 | name: String, |
@@ -47,8 +63,14 @@ impl Author { |
47 | 63 | } |
48 | 64 |
|
49 | 65 | fn main() -> Result<(), Box<Error>> { |
| 66 | + let opt = Cli::from_args(); |
50 | 67 | let curses: Vec<&str> = CURSES.lines().collect(); |
51 | | - let path = env::current_dir()?; |
| 68 | + let path; |
| 69 | + if opt.directory.is_none() { |
| 70 | + path = env::current_dir()?; |
| 71 | + } else { |
| 72 | + path = PathBuf::from(opt.directory.unwrap()); |
| 73 | + } |
52 | 74 | let repo = Repository::open(path)?; |
53 | 75 | let mut revwalk = repo.revwalk()?; |
54 | 76 | let mut commits: Vec<Commit> = Vec::new(); |
|
0 commit comments