new: build the target-distribution menu from supported_dists

This commit is contained in:
2026-09-18 13:10:46 +02:00
parent c106ebe315
commit 69f3c3954e
2 changed files with 17 additions and 5 deletions
+5 -2
View File
@@ -214,9 +214,12 @@ fn parse_series_csv(content: &str) -> Result<Vec<SeriesInformation>, Box<dyn Err
Ok(series_info_list) Ok(series_info_list)
} }
/// List the distributions known to pkh (e.g. "debian", "ubuntu") /// List the distributions known to pkh (e.g. "debian", "ubuntu"), sorted so
/// that menus and error messages derived from it are deterministic
pub fn supported_dists() -> Vec<String> { pub fn supported_dists() -> Vec<String> {
DATA.dist.keys().cloned().collect() let mut dists: Vec<String> = DATA.dist.keys().cloned().collect();
dists.sort();
dists
} }
/// Special changelog distribution marking an entry that has not been /// Special changelog distribution marking an entry that has not been
+12 -3
View File
@@ -437,17 +437,26 @@ async fn run_wizard(mut cli: NewCli) -> Result<NewOptions, Box<dyn Error>> {
cli.maintainer = Some(ask_text("Maintainer", &default, validate)?); cli.maintainer = Some(ask_text("Maintainer", &default, validate)?);
} }
// 11. Target distribution. // 11. Target distribution. The menu derives from the distro data pkh
// ships (sorted); ubuntu is moved to the front when present so it
// stays the menu's first entry and fallback default as it has always
// been — prompt::select positions on a default value, not an index.
if cli.dist.is_none() { if cli.dist.is_none() {
let vendor = crate::build::env::current_vendor().to_lowercase(); let vendor = crate::build::env::current_vendor().to_lowercase();
let options = vec!["ubuntu".to_string(), "debian".to_string()]; let mut options = crate::distro_info::supported_dists();
if let Some(pos) = options.iter().position(|d| d == "ubuntu")
&& pos > 0
{
let ubuntu = options.remove(pos);
options.insert(0, ubuntu);
}
let default = if options.contains(&vendor) { let default = if options.contains(&vendor) {
vendor vendor
} else { } else {
"ubuntu".to_string() "ubuntu".to_string()
}; };
let answer = select_from(DIST_LABEL, &options, &default, |answer| { let answer = select_from(DIST_LABEL, &options, &default, |answer| {
answer == "ubuntu" || answer == "debian" options.contains(&answer.to_string())
})?; })?;
cli.dist = Some(answer); cli.dist = Some(answer);
} }