diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-04-21 08:58:38 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-04-21 09:03:46 +0200 |
| commit | 2c12e8ff8324b3ebaa10ac8162af09f5da295e1b (patch) | |
| tree | 674d5988c5ca0a34e6931798467fed61b45da3cf /src/common/input | |
| parent | fix(release): beta tag breaks cargo install (diff) | |
| download | sl0ppij-2c12e8ff8324b3ebaa10ac8162af09f5da295e1b.tar.gz sl0ppij-2c12e8ff8324b3ebaa10ac8162af09f5da295e1b.tar.xz sl0ppij-2c12e8ff8324b3ebaa10ac8162af09f5da295e1b.zip | |
Change Config To Flag (#290)
This changes the `config` subcommand to a config flag.
Add option subcommand for now, for the clearing of default path.
Add `ZELLIJ_CONFIG` environment variable.
The configuration locations are now as follows:
* `--config` flag
* `ZELLIJ_CONFIG` environment variable
* default config location
in that order.
Diffstat (limited to 'src/common/input')
| -rw-r--r-- | src/common/input/config.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/common/input/config.rs b/src/common/input/config.rs index 1926b11c..17e1edf1 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,17 @@ 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 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); } |
