From: Ian Jackson Date: Sun, 6 Jun 2021 21:09:26 +0000 (+0100) Subject: otter: Break up main()'s arg parsing ready for prefs X-Git-Tag: otter-0.7.0~70 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a834608d2648a39cfe73812fb9eb7abe8c940e01;p=otter.git otter: Break up main()'s arg parsing ready for prefs Signed-off-by: Ian Jackson --- diff --git a/cli/otter.rs b/cli/otter.rs index 11b46dcd..aaaae3cc 100644 --- a/cli/otter.rs +++ b/cli/otter.rs @@ -100,9 +100,8 @@ fn main() { ssh_command: Option, ssh_proxy_command: Option, } - let (subcommand, subargs, mo) = parse_args::( - env::args().collect(), - &|rma|{ + + let apmaker: ApMaker = &|rma|{ use argparse::*; let mut ap = ArgumentParser::new(); ap.stop_on_first_argument(true); @@ -214,7 +213,9 @@ fn main() { "directory for table and game specs"); ap - }, &|RawMainArgs { + }; + + let ap_completer = |RawMainArgs { account, nick, timezone, access, server, verbose, config_filename, superuser, subcommand, subargs, spec_dir, layout, game, @@ -304,7 +305,9 @@ fn main() { ssh_proxy_command, sc, })) - }, Some(&|w|{ + }; + + let extra_help: ExtraHelp = &|w|{ writeln!(w, "\nSubcommands:")?; let maxlen = inventory::iter::.into_iter() .map(|Subcommand{verb,..}| verb.len()) @@ -313,7 +316,14 @@ fn main() { writeln!(w, " {:width$} {}", verb, help, width=maxlen)?; } Ok(()) - })); + }; + + let (subcommand, subargs, mo) = parse_args::( + env::args().collect(), + &apmaker, + &ap_completer, + Some(&extra_help), + ); let stdout = CookedStdout::new(); let mut subargs = subargs;