substrate_manager/util/
command_prelude.rs1use clap::{Arg, ArgAction, Command};
2
3pub trait AppExt: Sized {
4 fn _arg(self, arg: Arg) -> Self;
5
6 fn arg_quiet(self) -> Self {
7 self._arg(flag("quiet", "Do not print cargo log messages").short('q'))
8 }
9}
10
11impl AppExt for Command {
12 fn _arg(self, arg: Arg) -> Self {
13 self.arg(arg)
14 }
15}
16
17pub fn subcommand(name: &'static str) -> Command {
18 Command::new(name)
19 }
23
24pub fn opt(name: &'static str, help: &'static str) -> Arg {
25 Arg::new(name).long(name).help(help).action(ArgAction::Set)
26}
27
28pub fn flag(name: &'static str, help: &'static str) -> Arg {
29 Arg::new(name)
30 .long(name)
31 .help(help)
32 .action(ArgAction::SetTrue)
33}
34
35#[track_caller]
36pub fn ignore_unknown<T: Default>(r: Result<T, clap::parser::MatchesError>) -> T {
37 match r {
38 Ok(t) => t,
39 Err(clap::parser::MatchesError::UnknownArgument { .. }) => Default::default(),
40 Err(e) => {
41 panic!("Mismatch between definition and access: {}", e);
42 }
43 }
44}