diff options
author | Teddy Wing | 2020-08-01 20:13:08 +0200 |
---|---|---|
committer | Teddy Wing | 2020-08-01 20:13:08 +0200 |
commit | d64951ef8fc55733d6b87a0ea6f1a16186eba3d2 (patch) | |
tree | f63c1a6903f22f7c57128fa52d305bc8a5cb36ba /src/config.rs | |
parent | ed17b139448c2c0ecc7b7f02f11a6b57939f8f90 (diff) | |
download | git-suggestion-d64951ef8fc55733d6b87a0ea6f1a16186eba3d2.tar.bz2 |
Config: Extract `remote` into function
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 25 |
1 files changed, 16 insertions, 9 deletions
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<Option<String>, 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 { |