convert introspect::Argument::new to ::try_new

This commit is contained in:
Brad Warren
2026-06-18 11:09:53 -07:00
committed by Will Greenberg
parent 9280067e31
commit d122ce6e6d
+12 -5
View File
@@ -2,6 +2,7 @@
//! serializable by serde.
use std::collections::HashMap;
use anyhow::Context;
use serde::Serialize;
use crate::modifiers;
@@ -50,16 +51,22 @@ struct Subcommand<'a> {
}
impl Argument<'_> {
fn new<'a>(
fn try_new<'a>(
argument: &'a clap::Arg,
modifier: &modifiers::ArgumentModifier<'static>,
) -> Option<Argument<'a>> {
) -> anyhow::Result<Argument<'a>> {
// if an argument doesn't have the data we need, it's silently dropped from the GUI, however,
// tests should prevent this from happening and we could add logging messages about this in
// the future if desired
Some(Argument {
let partial_flag = argument.get_long().with_context(|| {
format!(
"Missing long form command line flag for {}",
argument.get_id().as_str(),
)
})?;
Ok(Argument {
advanced: modifier.advanced,
flag: format!("--{}", argument.get_long()?),
flag: format!("--{}", partial_flag),
label: modifier.gui_label,
takes_values: argument.get_action().takes_values(),
})
@@ -86,7 +93,7 @@ impl Subcommand<'_> {
.filter_map(|arg_modifier| {
argument_map
.get(arg_modifier.clap_id)
.and_then(|arg| Argument::new(arg, arg_modifier))
.and_then(|arg| Argument::try_new(arg, arg_modifier).ok())
})
.collect(),
command: modifier.command,