diff options
| author | Teddy Wing | 2020-08-02 10:23:52 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2020-08-02 10:23:52 +0200 | 
| commit | 20e98432afb02262703a2bd4524e6a87f3145086 (patch) | |
| tree | d3ba5721e1cecab3f35ef243f56bfab69a6b6c88 | |
| parent | 4151c8aee043bc4d39a7083b52ee5996adb22de8 (diff) | |
| download | git-suggestion-20e98432afb02262703a2bd4524e6a87f3145086.tar.bz2 | |
git-sugapply: Copy over new logic from `git-sugpatch`
Use the new logic from `git-sugpatch` to build a `Config` and run
`apply()` on all suggestion input arguments.
| -rw-r--r-- | src/bin/git-sugapply.rs | 42 | 
1 files changed, 30 insertions, 12 deletions
| diff --git a/src/bin/git-sugapply.rs b/src/bin/git-sugapply.rs index 157405d..96e4423 100644 --- a/src/bin/git-sugapply.rs +++ b/src/bin/git-sugapply.rs @@ -1,25 +1,43 @@  use std::env;  use std::process; -use github_suggestion::{Client, SuggestionUrl}; +use exitcode; + +use github_suggestion_cli::{gseprintln, for_suggestion}; +use github_suggestion_cli::config::Config;  fn main() {      let args: Vec<_> = env::args().collect(); -    if args.len() < 2 { -        process::exit(111); -    } +    let config = match Config::get( +        &args, +        "usage: git sugapply [options] <suggestion>...", +    ) { +        Ok(c) => c, +        Err(e) => { +            gseprintln!(e); -    let url: SuggestionUrl = args[1].parse().unwrap(); +            process::exit(exitcode::CONFIG); +        }, +    }; -    let client = Client::new( -        env!("GITHUB_TOKEN"), -        &url.owner, -        &url.repo, -    ).unwrap(); +    if config.suggestions.is_empty() { +        config.print_usage(); -    let suggestion = client.fetch(&url.comment_id).unwrap(); +        process::exit(exitcode::USAGE); +    } -    suggestion.apply().unwrap(); +    for_suggestion( +        &config, +        |suggestion| { +            match suggestion.apply() { +                Err(e) => { +                    gseprintln!(e); +                    process::exit(exitcode::UNAVAILABLE); +                }, +                _ => (), +            } +        }, +    );  } | 
