From 20e98432afb02262703a2bd4524e6a87f3145086 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Aug 2020 10:23:52 +0200 Subject: 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. --- src/bin/git-sugapply.rs | 42 ++++++++++++++++++++++++++++++------------ 1 file 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] ...", + ) { + 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); + }, + _ => (), + } + }, + ); } -- cgit v1.2.3