From d64951ef8fc55733d6b87a0ea6f1a16186eba3d2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 1 Aug 2020 20:13:08 +0200 Subject: Config: Extract `remote` into function --- src/config.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 615c0d4..9b37eb1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -43,15 +43,9 @@ impl Config { let git_config = Repository::open(".")?.config()?; - let remote = match opt_matches.opt_str("remote") { - Some(r) => Ok(Some(r)), - None => match git_config.get_string(&git_config_key("remote")) { - Err(e) if e.code() == git2::ErrorCode::NotFound => Ok(None), - r => r.map(|r| Some(r)), - }, - }?; - - let o_r = OwnerRepo::from_remote(remote.as_deref())?; + 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)?, @@ -75,6 +69,19 @@ impl Config { }, } } + + fn remote( + opt_matches: &getopts::Matches, + git_config: &git2::Config, + ) -> Result, git2::Error> { + match opt_matches.opt_str("remote") { + Some(r) => Ok(Some(r)), + None => match git_config.get_string(&git_config_key("remote")) { + Err(e) if e.code() == git2::ErrorCode::NotFound => Ok(None), + r => r.map(|r| Some(r)), + }, + } + } } fn git_config_key(key: &str) -> String { -- cgit v1.2.3