Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(setup): switch setup order #765

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions zellij-utils/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(());
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down