let text = format!(
"'{name}:{help}' \\",
name = name,
- help = escape_help(subcommand.get_about().unwrap_or(""))
+ help = escape_help(&subcommand.get_about().unwrap_or_default().to_string())
);
- if !text.is_empty() {
- ret.push(text);
- }
+ ret.push(text);
}
// The subcommands
);
let mut segments = vec![format!("({})", name)];
let subcommand_args = get_args_of(
- parser_of(parent, &*bin_name).expect(INTERNAL_ERROR_MSG),
+ parser_of(parent, bin_name).expect(INTERNAL_ERROR_MSG),
Some(parent),
);
}
// Get the help text of all child subcommands.
- let children = get_subcommands_of(parser_of(parent, &*bin_name).expect(INTERNAL_ERROR_MSG));
+ let children = get_subcommands_of(parser_of(parent, bin_name).expect(INTERNAL_ERROR_MSG));
if !children.is_empty() {
segments.push(children);
//
// Given the bin_name "a b c" and the Command for "a" this returns the "c" Command.
// Given the bin_name "a b c" and the Command for "b" this returns the "c" Command.
-fn parser_of<'help, 'cmd>(
- parent: &'cmd Command<'help>,
- bin_name: &str,
-) -> Option<&'cmd Command<'help>> {
+fn parser_of<'cmd>(parent: &'cmd Command, bin_name: &str) -> Option<&'cmd Command> {
debug!("parser_of: p={}, bin_name={}", parent.get_name(), bin_name);
- if bin_name == parent.get_bin_name().unwrap_or(&String::new()) {
+ if bin_name == parent.get_bin_name().unwrap_or_default() {
return Some(parent);
}
// Uses either `possible_vals` or `value_hint` to give hints about possible argument values
fn value_completion(arg: &Arg) -> Option<String> {
- if let Some(values) = &arg.get_possible_values() {
+ if let Some(values) = crate::generator::utils::possible_values(arg) {
if values
.iter()
.any(|value| !value.is_hide_set() && value.get_help().is_some())
Some(format!(
r#"{name}\:"{tooltip}""#,
name = escape_value(value.get_name()),
- tooltip = value.get_help().map(escape_help).unwrap_or_default()
+ tooltip =
+ escape_help(&value.get_help().unwrap_or_default().to_string()),
))
}
})
values
.iter()
.filter(|pv| !pv.is_hide_set())
- .map(PossibleValue::get_name)
+ .map(|n| n.get_name())
.collect::<Vec<_>>()
.join(" ")
))
for o in p.get_opts() {
debug!("write_opts_of:iter: o={}", o.get_id());
- let help = o.get_help().map_or(String::new(), escape_help);
+ let help = escape_help(&o.get_help().unwrap_or_default().to_string());
let conflicts = arg_conflicts(p, o, p_global);
- let multiple = if o.is_multiple_occurrences_set() {
+ let multiple = if let ArgAction::Count | ArgAction::Append = o.get_action() {
"*"
} else {
""
Some(val) => format!(":{}:{}", vn, val),
None => format!(":{}: ", vn),
};
- let vc = match o.get_num_vals() {
- Some(num_vals) => vc.repeat(num_vals),
- None => vc,
- };
+ let vc = vc.repeat(o.get_num_args().expect("built").min_values());
if let Some(shorts) = o.get_short_and_visible_aliases() {
for short in shorts {
for f in utils::flags(p) {
debug!("write_flags_of:iter: f={}", f.get_id());
- let help = f.get_help().map_or(String::new(), escape_help);
+ let help = escape_help(&f.get_help().unwrap_or_default().to_string());
let conflicts = arg_conflicts(p, &f, p_global);
- let multiple = if f.is_multiple_occurrences_set() {
+ let multiple = if let ArgAction::Count | ArgAction::Append = f.get_action() {
"*"
} else {
""
for arg in p.get_positionals() {
debug!("write_positionals_of:iter: arg={}", arg.get_id());
- let cardinality = if arg.is_multiple_values_set() || arg.is_multiple_occurrences_set() {
+ let num_args = arg.get_num_args().expect("built");
+ let cardinality = if num_args.max_values() > 1 {
"*:"
} else if !arg.is_required_set() {
":"
name = arg.get_id(),
help = arg
.get_help()
- .map_or("".to_owned(), |v| " -- ".to_owned() + v)
+ .map(|s| s.to_string())
+ .map_or("".to_owned(), |v| " -- ".to_owned() + &v)
.replace('[', "\\[")
.replace(']', "\\]")
.replace('\'', "'\\''")
.replace(':', "\\:"),
- value_completion = value_completion(arg).unwrap_or_else(|| "".to_string())
+ value_completion = value_completion(arg).unwrap_or_default()
);
debug!("write_positionals_of:iter: Wrote...{}", a);