mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-06-19 02:49:43 -07:00
convert introspect::Argument::new to ::try_new
This commit is contained in:
committed by
Will Greenberg
parent
9280067e31
commit
d122ce6e6d
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user