summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-06-22 11:07:09 -0400
committerDan Davison <dandavison7@gmail.com>2020-06-22 12:05:37 -0400
commit83e020d43e143852aebe1c64e15edd2ba4b13756 (patch)
tree57d523665c16077c6ad6839f561d2b66d79c6a7c /src/cli.rs
parentf635d87938a0b3d74e90e8e0e9aadb65e7d3bb93 (diff)
Refactor: separate Opt construction from Config construction
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index bdf9617f..c05874be 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -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
+ }
+}