use super::{IcrcCommand, command};
use crate::cli::clap::parsed_options;
use clap::Command as ClapCommand;
#[test]
fn every_icrc_leaf_decodes_through_the_typed_tree() {
fn collect_leaves(command: &ClapCommand, path: Vec<String>, leaves: &mut Vec<Vec<String>>) {
if command.has_subcommands() {
for child in command
.get_subcommands()
.filter(|child| child.get_name() != "help")
{
let mut child_path = path.clone();
child_path.push(child.get_name().to_string());
collect_leaves(child, child_path, leaves);
}
} else {
let mut args = path;
let mut required: Vec<_> = command
.get_arguments()
.filter(|arg| arg.is_positional() && arg.is_required_set())
.collect();
required.sort_by_key(|arg| arg.get_index());
args.extend(
required
.into_iter()
.map(|_| "ryjl3-tyaaa-aaaaa-aaaba-cai".to_string()),
);
leaves.push(args);
}
}
let command = crate::prepare_command_tree(command());
let mut leaves = Vec::new();
collect_leaves(&command, vec!["icrc".to_string()], &mut leaves);
for args in leaves {
let matches = command
.clone()
.try_get_matches_from(&args)
.unwrap_or_else(|error| panic!("{args:?}: {error}"));
let _: IcrcCommand = parsed_options(&matches);
}
}