Skip to content

Commit

Permalink
feat: re-add ask config onboard ui
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Jan 7, 2025
1 parent 5589cc9 commit eceac4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cli/src/actions/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dialoguer::{theme::ColorfulTheme, Confirm, FuzzySelect, Input};
use log::info;

use crate::{
config::{ask_for_init_config, patch_instance_config, patch_workspace_config},
config::{ask_for_config, patch_instance_config, patch_workspace_config},
download::{download_file, pick_latest_rootfs, CIEL_MAINLINE_ARCHS, CIEL_RETRO_ARCHS},
logger::style_bool,
make_progress_bar,
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn new_workspace(args: &ArgMatches) -> Result<()> {
if arch.is_none() {
arch = Some(ask_for_target_arch()?.to_owned())
}
ask_for_init_config(&mut config)?;
ask_for_config(&mut config)?;
} else {
info!("Running in unattended mode, using default configuration ...");
}
Expand Down
27 changes: 26 additions & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ use log::info;

use crate::utils::get_host_arch_name;

const WORKSPACE_ARGS: &[&str] = &[
"maintainer",
"dnssec",
"repo",
"local-repo",
"source-cache",
"nspawn-opt",
"branch-exclusive-output",
"volatile-mount",
"use-apt",
];

#[inline]
fn config_list<V>(args: &ArgMatches, id: &str, list: &mut Vec<V>)
where
Expand Down Expand Up @@ -81,6 +93,19 @@ pub fn config_instance(instance: &str, args: &ArgMatches) -> Result<()> {

/// Applies workspace configuration patches from [ArgMatches].
pub fn patch_workspace_config(args: &ArgMatches, config: &mut WorkspaceConfig) -> Result<()> {
let mut has_args = false;
for i in WORKSPACE_ARGS {
if args.get_raw(i).is_some() {
has_args = true;
break;
}
}

if !has_args {
ask_for_config(config)?;
return Ok(());
}

if let Some(maintainer) = args.get_one::<String>("maintainer") {
if maintainer != &config.maintainer {
WorkspaceConfig::validate_maintainer(maintainer)?;
Expand Down Expand Up @@ -138,7 +163,7 @@ pub fn patch_instance_config(args: &ArgMatches, config: &mut InstanceConfig) ->
}

/// Shows a series of prompts to let the user select the configurations
pub fn ask_for_init_config(config: &mut WorkspaceConfig) -> Result<()> {
pub fn ask_for_config(config: &mut WorkspaceConfig) -> Result<()> {
let theme = ColorfulTheme::default();
config.maintainer = Input::<String>::with_theme(&theme)
.with_prompt("Maintainer")
Expand Down

0 comments on commit eceac4a

Please sign in to comment.