diff options
| author | Teddy Wing | 2021-06-05 13:21:33 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-06-05 13:21:33 +0200 | 
| commit | 347c54c504b85197ecbe9bbfccf8589235a5a000 (patch) | |
| tree | a145c490736d6674335aab54ec61d81209388e62 | |
| parent | 2a05b269344ab324aa73a634256a0b82fa79f201 (diff) | |
| download | reflectub-347c54c504b85197ecbe9bbfccf8589235a5a000.tar.bz2 | |
Move command line option parsing code to `run()`
| -rw-r--r-- | src/main.rs | 57 | 
1 files changed, 25 insertions, 32 deletions
| diff --git a/src/main.rs b/src/main.rs index f21f00a..9f8d74b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,30 @@ use std::process;  #[tokio::main]  async fn main() { +    // let repos = github::fetch_repos("teddywing").await.unwrap(); +    // +    // dbg!(&repos); + +    // git::mirror( +    //     "https://github.com/teddywing/google-calendar-rsvp.git", +    //     Path::new("/tmp/grsvp"), +    // ).unwrap(); + +    // git::update( +    //     Path::new("/tmp/grsvp"), +    // ).unwrap(); + +    run().await.unwrap(); +} + +fn print_usage(opts: &Options) { +    print!( +        "{}", +        opts.usage("usage: reflectub [options] -d DATABASE <github_username> <repository_path>"), +    ); +} + +async fn run() -> anyhow::Result<()> {      let args: Vec<String> = env::args().collect();      let mut opts = Options::new(); @@ -26,14 +50,7 @@ async fn main() {      opts.optflag("h", "help", "print this help menu");      opts.optflag("V", "version", "show the program version"); -    let opt_matches = match opts.parse(&args[1..]) { -        Ok(m) => m, -        Err(e) => { -            eprintln!("error: {}", e); - -            process::exit(exitcode::SOFTWARE); -        }, -    }; +    let opt_matches = opts.parse(&args[1..])?;      if opt_matches.opt_present("h") {          print_usage(&opts); @@ -50,30 +67,6 @@ async fn main() {          process::exit(exitcode::USAGE);      } -    // let repos = github::fetch_repos("teddywing").await.unwrap(); -    // -    // dbg!(&repos); - -    // git::mirror( -    //     "https://github.com/teddywing/google-calendar-rsvp.git", -    //     Path::new("/tmp/grsvp"), -    // ).unwrap(); - -    // git::update( -    //     Path::new("/tmp/grsvp"), -    // ).unwrap(); - -    run().await.unwrap(); -} - -fn print_usage(opts: &Options) { -    print!( -        "{}", -        opts.usage("usage: reflectub [options] -d DATABASE <github_username> <repository_path>"), -    ); -} - -async fn run() -> anyhow::Result<()> {      let test_repos = vec