From 0ca28486a5f637e977c30297232fa81650ae50b4 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Tue, 5 Oct 2021 13:43:05 +0200 Subject: [PATCH] fix(setup): switch setup order (#765) - commands that don't use the config file now wont throw an error on malformed config files --- zellij-utils/src/setup.rs | 47 ++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 730014610..975ff333c 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -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,20 +201,22 @@ impl Setup { }; if let Some(Command::Setup(ref setup)) = &opts.command { - setup.from_cli(opts, &config_options).map_or_else( - |e| { - eprintln!("{:?}", e); - process::exit(1); - }, - |_| {}, - ); + setup + .from_cli_with_options(opts, &config_options) + .map_or_else( + |e| { + eprintln!("{:?}", e); + process::exit(1); + }, + |_| {}, + ); }; Ok((config, layout, config_options)) } /// 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);