summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortummychow <tummychow@users.noreply.github.com>2018-02-15 12:54:26 -0800
committertummychow <tummychow@users.noreply.github.com>2018-02-15 13:16:42 -0800
commit2a0c789a031ed10f51669618aa824779a616a710 (patch)
tree9110b90ad8b68c18af29db3afbb0227cefcc835b
parente7d10d5f0a00535f5d29eead74d043f1d9cd7dfd (diff)
add cli args
-rw-r--r--src/lib.rs16
-rw-r--r--src/main.rs31
2 files changed, 43 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a0abfcb..ada8d97 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,13 @@ extern crate git2;
use std::error::Error;
-pub fn run() -> Result<(), Box<Error>> {
+pub struct Config {
+ pub dry_run: bool,
+ pub force: bool,
+ pub verbose: bool,
+}
+
+pub fn run(config: &Config) -> Result<(), Box<Error>> {
let repo = git2::Repository::open_from_env()?;
println!("{:?}", repo.path());
@@ -15,6 +21,12 @@ mod tests {
#[test]
fn test_run() {
- assert!(run().is_ok());
+ assert!(
+ run(&Config {
+ dry_run: false,
+ force: false,
+ verbose: false,
+ }).is_ok()
+ );
}
}
diff --git a/src/main.rs b/src/main.rs
index e65cbb4..8faa240 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,10 +5,37 @@ extern crate git_absorb;
use std::process;
fn main() {
- let args = app_from_crate!().get_matches();
+ let args = app_from_crate!()
+ .about("Automatically absorb staged changes into your current branch")
+ .arg(
+ clap::Arg::with_name("dry-run")
+ .help("Don't make any actual changes")
+ .short("n")
+ .long("dry-run")
+ .takes_value(false),
+ )
+ .arg(
+ clap::Arg::with_name("force")
+ .help("Skip safety checks")
+ .short("f")
+ .long("force")
+ .takes_value(false),
+ )
+ .arg(
+ clap::Arg::with_name("verbose")
+ .help("Display more output")
+ .short("v")
+ .long("verbose")
+ .takes_value(false),
+ )
+ .get_matches();
println!("{:?}", args);
- if let Err(e) = git_absorb::run() {
+ if let Err(e) = git_absorb::run(&git_absorb::Config {
+ dry_run: args.is_present("dry-run"),
+ force: args.is_present("force"),
+ verbose: args.is_present("verbose"),
+ }) {
eprintln!("error: {:?}", e);
process::exit(1);
}