fix(setup): switch setup order
commands that don't use the config file now wont throw an error on
malformed config files
@@ -159,6 +159,17 @@ impl Setup {
_ => false,
};
+ // setup functions that don't require deserialisation of the config
+ if let Some(Command::Setup(ref setup)) = &opts.command {
+ setup.from_cli().map_or_else(
+ |e| {
+ eprintln!("{:?}", e);
+ process::exit(1);
+ },
+ |_| {},
+ );
+ };
+
let config = if !clean {
match Config::try_from(opts) {
Ok(config) => config,
@@ -190,7 +201,9 @@ impl Setup {
};
if let Some(Command::Setup(ref setup)) = &opts.command {
- setup.from_cli(opts, &config_options).map_or_else(
+ setup
+ .from_cli_with_options(opts, &config_options)
+ .map_or_else(
|e| {
eprintln!("{:?}", e);
process::exit(1);
@@ -203,7 +216,7 @@ impl Setup {
}
/// General setup helpers
- pub fn from_cli(&self, opts: &CliArgs, config_options: &Options) -> std::io::Result<()> {
+ pub fn from_cli(&self) -> std::io::Result<()> {
if self.clean {
return Ok(());
}
@@ -213,11 +226,6 @@ impl Setup {
std::process::exit(0);
}
- if self.check {
- Setup::check_defaults_config(opts, config_options)?;
- std::process::exit(0);
- }
-
if let Some(shell) = &self.generate_completion {
Self::generate_completion(shell.into());
std::process::exit(0);
@@ -231,6 +239,19 @@ impl Setup {
Ok(())
}
+ /// Checks the merged configuration
+ pub fn from_cli_with_options(
+ &self,
+ opts: &CliArgs,
+ config_options: &Options,
+ ) -> std::io::Result<()> {
+ if self.check {
+ Setup::check_defaults_config(opts, config_options)?;
+ std::process::exit(0);
+ }
+ Ok(())
+ }
+
pub fn check_defaults_config(opts: &CliArgs, config_options: &Options) -> std::io::Result<()> {
let data_dir = opts.data_dir.clone().unwrap_or_else(get_default_data_dir);
let config_dir = opts.config_dir.clone().or_else(find_default_config_dir);
