diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-04-21 10:05:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-21 10:05:45 +0200 |
| commit | 4863fb7b5e0b852f3e6c00410c486e548d36eab2 (patch) | |
| tree | e3c4c7cf37ddaf282e577a19a10194d337d181c2 /src | |
| parent | fix(release): beta tag breaks cargo install (diff) | |
| parent | Chore(Rustfmt) (diff) | |
| download | sl0ppij-4863fb7b5e0b852f3e6c00410c486e548d36eab2.tar.gz sl0ppij-4863fb7b5e0b852f3e6c00410c486e548d36eab2.tar.xz sl0ppij-4863fb7b5e0b852f3e6c00410c486e548d36eab2.zip | |
Merge pull request #300 from a-kenji/config-command
Change Config To Flag (#290)
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli.rs | 14 | ||||
| -rw-r--r-- | src/common/input/config.rs | 24 | ||||
| -rw-r--r-- | src/common/mod.rs | 2 |
3 files changed, 23 insertions, 17 deletions
@@ -1,6 +1,9 @@ use std::path::PathBuf; use structopt::StructOpt; +// TODO add to consts.rs +const ZELLIJ_CONFIG_ENV: &str = "ZELLIJ_CONFIG"; + #[derive(StructOpt, Default, Debug)] #[structopt(name = "zellij")] pub struct CliArgs { @@ -28,8 +31,12 @@ pub struct CliArgs { #[structopt(short, long)] pub layout: Option<PathBuf>, + /// Change where zellij looks for the configuration + #[structopt(short, long, env=ZELLIJ_CONFIG_ENV)] + pub config: Option<PathBuf>, + #[structopt(subcommand)] - pub config: Option<ConfigCli>, + pub option: Option<ConfigCli>, #[structopt(short, long)] pub debug: bool, @@ -37,10 +44,9 @@ pub struct CliArgs { #[derive(Debug, StructOpt)] pub enum ConfigCli { - /// Path to the configuration yaml file - #[structopt(alias = "c")] + /// Change the behaviour of zellij + #[structopt(name = "option")] Config { - path: Option<PathBuf>, #[structopt(long)] /// Disables loading of configuration file at default location clean: bool, diff --git a/src/common/input/config.rs b/src/common/input/config.rs index 1926b11c..542116d9 100644 --- a/src/common/input/config.rs +++ b/src/common/input/config.rs @@ -79,19 +79,23 @@ impl Config { /// Entry point of the configuration #[cfg(not(test))] - pub fn from_cli_config(cli_config: Option<ConfigCli>) -> ConfigResult { + pub fn from_cli_config( + location: Option<PathBuf>, + cli_config: Option<ConfigCli>, + ) -> ConfigResult { + if let Some(path) = location { + return Config::new(&path); + } + match cli_config { Some(ConfigCli::Config { clean, .. }) if clean => Ok(Config::default()), - Some(ConfigCli::Config { path, .. }) if path.is_some() => { - Ok(Config::new(&path.unwrap())?) - } Some(_) | None => Ok(Config::from_default_path()?), } } /// In order not to mess up tests from changing configurations #[cfg(test)] - pub fn from_cli_config(_: Option<ConfigCli>) -> ConfigResult { + pub fn from_cli_config(_: Option<PathBuf>, _: Option<ConfigCli>) -> ConfigResult { Ok(Config::default()) } } @@ -137,19 +141,15 @@ mod config_test { #[test] fn clean_option_equals_default_config() { - let no_file = PathBuf::from(r"../fixtures/config/config.yamlll"); - let cli_config = ConfigCli::Config { - path: Some(no_file), - clean: true, - }; - let config = Config::from_cli_config(Some(cli_config)).unwrap(); + let cli_config = ConfigCli::Config { clean: true }; + let config = Config::from_cli_config(None, Some(cli_config)).unwrap(); let default = Config::default(); assert_eq!(config, default); } #[test] fn no_config_option_file_equals_default_config() { - let config = Config::from_cli_config(None).unwrap(); + let config = Config::from_cli_config(None, None).unwrap(); let default = Config::default(); assert_eq!(config, default); } diff --git a/src/common/mod.rs b/src/common/mod.rs index 860d12db..e2cd2220 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -128,7 +128,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { .write(take_snapshot.as_bytes()) .unwrap(); - let config = Config::from_cli_config(opts.config) + let config = Config::from_cli_config(opts.config, opts.option) .map_err(|e| { eprintln!("There was an error in the config file:\n{}", e); std::process::exit(1); |
