new: validate the command name before generating files

The command/binary name was accepted verbatim and interpolated into
debian/install, debian/rules, debian/tests/smoke, automake variables,
meson.build and [project.scripts]: a value with a space or quote broke
the install lines and shell snippets, 'my.tool' parsed as a nested TOML
table (silently dropping the console script) and produced non-canonical
automake variable names. Both --command and the wizard answer now go
through a shared validator (lowercase identifier: letters, digits,
+ - . _).
This commit is contained in:
2026-09-17 17:03:43 +02:00
parent d5b76ec8d8
commit dd006f7b80
2 changed files with 64 additions and 4 deletions
+5 -4
View File
@@ -383,15 +383,16 @@ async fn run_wizard(mut cli: NewCli) -> Result<NewOptions, Box<dyn Error>> {
}
// 9. Command name (skipped for the empty template, where nothing is
// installed). The probed default must pass the required-answer check
// too, or the question is asked without one.
// installed). Typed answers and the offered default go through the
// same `validate_command` bar as `resolve` applies (which also
// requires a non-empty answer), so an unusable probe is withheld and
// invalid input re-asks here instead of failing late in `resolve`.
if cli.command.is_none() && template != TemplateId::Empty {
let default = probe
.as_ref()
.and_then(|p| p.command.clone())
.unwrap_or_else(|| cli.name.clone().unwrap_or_default());
let validate = required_answer("the command name");
let command = ask_text("Command name", &default, validate)?;
let command = ask_text("Command name", &default, options::validate_command)?;
cli.command = Some(command);
}