Skip to content

Commit a55ab94

Browse files
committed
Add structopt, you can now see commits in arbitrary directories
1 parent c6c5834 commit a55ab94

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-anger-management"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Sondre Nilsen <nilsen.sondre@gmail.com>"]
55
homepage = "https://github.com/sondr3/git-anger-management"
66
description = "Count your naughty words in git commit messages"
@@ -21,3 +21,4 @@ fail-on-warnings = []
2121

2222
[dependencies]
2323
git2 = "0.7"
24+
structopt = "0.2"

src/main.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
22
#![forbid(unsafe_code)]
33
extern crate git2;
4+
#[macro_use]
5+
extern crate structopt;
46

57
use git2::{Commit, Repository};
68
use std::cmp::PartialEq;
79
use std::collections::HashMap;
810
use std::env;
11+
use std::path::PathBuf;
912
use std::error::Error;
13+
use structopt::clap::AppSettings;
14+
use structopt::StructOpt;
1015

1116
static CURSES: &str = include_str!("words.txt");
1217

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+
1329
#[derive(Debug, Eq)]
1430
struct Author {
1531
name: String,
@@ -47,8 +63,14 @@ impl Author {
4763
}
4864

4965
fn main() -> Result<(), Box<Error>> {
66+
let opt = Cli::from_args();
5067
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+
}
5274
let repo = Repository::open(path)?;
5375
let mut revwalk = repo.revwalk()?;
5476
let mut commits: Vec<Commit> = Vec::new();

0 commit comments

Comments
 (0)