Skip to content

Commit b0641ea

Browse files
committed
cli: improve UX for the config command ...
... we need to allow the user to specify -g when the environment variable contain CIEL_INST. It would be very inconvenient to unset them before using config
1 parent d9a15ab commit b0641ea

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Diff for: src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn build_cli() -> Command {
104104
.subcommand(
105105
Command::new("config")
106106
.arg(instance_arg.clone().help("Instance to be configured"))
107-
.arg(Arg::new("g").short('g').action(clap::ArgAction::SetTrue).conflicts_with("INSTANCE").help("Configure base system instead of an instance"))
107+
.arg(Arg::new("g").short('g').action(clap::ArgAction::SetTrue).help("Configure base system instead of an instance"))
108108
.about("Configure system and toolchain for building interactively"),
109109
)
110110
.subcommand(

Diff for: src/main.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,32 @@ fn main() -> Result<()> {
233233
print_error!({ actions::update_os(force_use_apt,) });
234234
}
235235
("config", args) => {
236-
if args.get_flag("g") {
236+
// HACK: To improve UX, we allow -i and -g to be implicitly specified through environment variable
237+
// and then we check if user explicitly specified -i
238+
let has_global_flag = args.get_flag("g");
239+
let instance = get_instance_option(args).ok();
240+
let instance_from_env = if let Some(ref inst) = instance {
241+
std::env::var("CIEL_INST")
242+
.map(|x| &x == inst)
243+
.unwrap_or(false)
244+
} else {
245+
true
246+
};
247+
if !instance_from_env && has_global_flag {
248+
error!("Cannot use -g and -i together.");
249+
process::exit(1);
250+
}
251+
if has_global_flag {
237252
print_error!({ actions::config_os(None) });
238253
return Ok(());
239254
}
240-
let instance = get_instance_option(args)?;
241-
print_error!({ actions::config_os(Some(&instance)) });
255+
if let Some(inst) = instance {
256+
info!("Configuring for {}", inst);
257+
print_error!({ actions::config_os(Some(&inst)) });
258+
return Ok(());
259+
}
260+
261+
return Err(anyhow!("No instance specified!"));
242262
}
243263
("mount", args) => {
244264
print_error!({ one_or_all_instance!(args, &actions::mount_fs) });

0 commit comments

Comments
 (0)