diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-22 11:07:09 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-22 12:05:37 -0400 |
commit | 83e020d43e143852aebe1c64e15edd2ba4b13756 (patch) | |
tree | 57d523665c16077c6ad6839f561d2b66d79c6a7c /src/cli.rs | |
parent | f635d87938a0b3d74e90e8e0e9aadb65e7d3bb93 (diff) |
Refactor: separate Opt construction from Config construction
Diffstat (limited to 'src/cli.rs')
-rw-r--r-- | src/cli.rs | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -1,7 +1,13 @@ +#[cfg(test)] +use std::ffi::OsString; use std::path::PathBuf; use structopt::clap::AppSettings::{ColorAlways, ColoredHelp, DeriveDisplayOrder}; -use structopt::StructOpt; +use structopt::{clap, StructOpt}; + +use crate::git_config::GitConfig; +use crate::rewrite_options; +use crate::set_options; #[derive(StructOpt, Clone, Debug, PartialEq)] #[structopt( @@ -473,3 +479,28 @@ pub struct Opt { /// Deprecated: use --syntax-theme. pub deprecated_theme: Option<String>, } + +impl Opt { + pub fn from_args_and_git_config(git_config: &mut Option<GitConfig>) -> Self { + Self::from_clap_and_git_config(Self::clap().get_matches(), git_config) + } + + #[cfg(test)] + pub fn from_iter_and_git_config<I>(iter: I, git_config: &mut Option<GitConfig>) -> Self + where + I: IntoIterator, + I::Item: Into<OsString> + Clone, + { + Self::from_clap_and_git_config(Self::clap().get_matches_from(iter), git_config) + } + + fn from_clap_and_git_config( + arg_matches: clap::ArgMatches, + git_config: &mut Option<GitConfig>, + ) -> Self { + let mut opt = Opt::from_clap(&arg_matches); + set_options::set_options(&mut opt, git_config, &arg_matches); + rewrite_options::apply_rewrite_rules(&mut opt, &arg_matches); + opt + } +} |