From 38a871f28bad90e238021d8cc46b9fa926f9df75 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Aug 2020 04:31:11 +0200 Subject: git-sugpatch: Error if no remote and suggestion ID argument We want to allow not having a remote when URL arguments are given, but require it when a suggestion ID argument is given (otherwise we wouldn't have an owner-repo pair to make the GitHub request). Had some trouble with the `OwnerRepo.o_r` value. It was being moved into the closure, so tried a loop. There was a similar problem with the loop. However, by returning, I was able to get a reference to the `Result` instead of having it be moved. --- src/config.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 7fe9695..bbee2c9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,8 +27,7 @@ pub enum Error { #[derive(Debug)] pub struct Config { pub github_token: String, - pub owner: String, - pub repo: String, + pub o_r: Result, pub suggestions: Vec, } @@ -46,12 +45,11 @@ impl Config { let o_r = OwnerRepo::from_remote( Self::remote(&opt_matches, &git_config)?.as_deref(), - )?; + ); Ok(Config { github_token: Self::github_token(&opt_matches, &git_config)?, - owner: o_r.owner, - repo: o_r.repo, + o_r: o_r, suggestions: opt_matches.free, }) } -- cgit v1.2.3