heck_string_cli/
dispatch.rs1pub trait ParserDispatcher<E: std::error::Error>: clap::Parser
2where
3 crate::Exit: From<std::result::Result<(), E>>,
4{
5 fn dispatch(&self) -> Result<(), E>;
6 fn dispatch_cargo(&self) -> Result<(), E> {
7 Ok(self.dispatch()?)
8 }
9 fn run() -> Result<(), E> {
10 let (args, is_cargo) = Self::args();
11 if is_cargo {
12 Self::dispatch_cargo(&Self::parse_from(&args))?;
13 } else {
14 Self::dispatch(&Self::parse_from(&args))?;
15 }
16 Ok(())
17 }
18 fn main() -> crate::Exit {
19 Self::run().into()
20 }
21 fn args() -> (Vec<String>, bool) {
22 let argv = std::env::args().map(|arg|arg.to_string()).collect::<Vec<String>>();
23
24 (argv, false)
25 }
26}
27pub trait SubcommandDispatcher<E: std::error::Error>: clap::Subcommand {
28 fn dispatch(&self) -> Result<(), E>;
29}
30
31pub trait ArgsDispatcher<E: std::error::Error>: clap::Args {
32 fn dispatch(&self) -> Result<(), E>;
33}