Skip to content

Commit

Permalink
Add fn for running the root cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Dec 18, 2023
1 parent 87279f4 commit c9ba372
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ pub struct Root {
cmd: Cmd,
}

impl Root {
pub fn run(&self) -> Result<(), Error> {
match &self.cmd {
Cmd::Types(c) => c.run(&self.channel),
Cmd::Guess(c) => c.run(&self.channel)?,
Cmd::Decode(c) => c.run(&self.channel)?,
Cmd::Encode(c) => c.run(&self.channel)?,
Cmd::Version => version::Cmd::run(),
}
Ok(())
}
}

#[derive(ValueEnum, Debug, Clone)]
pub enum Channel {
#[value(name = "+curr")]
Expand Down Expand Up @@ -78,12 +91,5 @@ where
T: Into<OsString> + Clone,
{
let root = Root::try_parse_from(args)?;
match root.cmd {
Cmd::Types(c) => c.run(&root.channel),
Cmd::Guess(c) => c.run(&root.channel)?,
Cmd::Decode(c) => c.run(&root.channel)?,
Cmd::Encode(c) => c.run(&root.channel)?,
Cmd::Version => version::Cmd::run(),
}
Ok(())
root.run()
}

0 comments on commit c9ba372

Please sign in to comment.