Skip to content

Commit

Permalink
refactor: Move sub-command definition to corresponding module (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Mar 18, 2022
1 parent 064c7e6 commit c8d888b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 61 deletions.
10 changes: 10 additions & 0 deletions src/bin/oura/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,13 @@ pub fn run(args: &ArgMatches) -> Result<(), Error> {

Ok(())
}

/// Creates the clap definition for this sub-command
pub(crate) fn command_definition<'a>() -> clap::Command<'a> {
clap::Command::new("daemon").arg(
clap::Arg::new("config")
.long("config")
.takes_value(true)
.help("config file to load by the daemon"),
)
}
31 changes: 31 additions & 0 deletions src/bin/oura/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,34 @@ pub fn run(args: &ArgMatches) -> Result<(), Error> {

Ok(())
}

/// Creates the clap definition for this sub-command
pub(crate) fn command_definition<'a>() -> clap::Command<'a> {
clap::Command::new("dump")
.arg(clap::Arg::new("socket").required(true))
.arg(
clap::Arg::new("bearer")
.long("bearer")
.takes_value(true)
.possible_values(&["tcp", "unix"]),
)
.arg(clap::Arg::new("magic").long("magic").takes_value(true))
.arg(
clap::Arg::new("since")
.long("since")
.takes_value(true)
.help("point in the chain to start reading from, expects format `slot,hex-hash`"),
)
.arg(
clap::Arg::new("mode")
.long("mode")
.takes_value(true)
.possible_values(&["node", "client"]),
)
.arg(
clap::Arg::new("output")
.long("output")
.takes_value(true)
.help("path-like prefix for the log files (fallbacks to stdout output)"),
)
}
65 changes: 4 additions & 61 deletions src/bin/oura/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod watch;

use std::process;

use clap::{Arg, Command};
use clap::Command;

type Error = oura::Error;

Expand All @@ -13,66 +13,9 @@ fn main() {
.name("oura")
.about("the tail of cardano")
.version(env!("CARGO_PKG_VERSION"))
.subcommand(
Command::new("watch")
.arg(Arg::new("socket").required(true))
.arg(
Arg::new("bearer")
.long("bearer")
.takes_value(true)
.possible_values(&["tcp", "unix"]),
)
.arg(Arg::new("magic").long("magic").takes_value(true))
.arg(Arg::new("since").long("since").takes_value(true).help(
"point in the chain to start reading from, expects format `slot,hex-hash`",
))
.arg(
Arg::new("throttle")
.long("throttle")
.takes_value(true)
.help("milliseconds to wait between output lines (for easier reading)"),
)
.arg(
Arg::new("mode")
.long("mode")
.takes_value(true)
.possible_values(&["node", "client"]),
),
)
.subcommand(
Command::new("dump")
.arg(Arg::new("socket").required(true))
.arg(
Arg::new("bearer")
.long("bearer")
.takes_value(true)
.possible_values(&["tcp", "unix"]),
)
.arg(Arg::new("magic").long("magic").takes_value(true))
.arg(Arg::new("since").long("since").takes_value(true).help(
"point in the chain to start reading from, expects format `slot,hex-hash`",
))
.arg(
Arg::new("mode")
.long("mode")
.takes_value(true)
.possible_values(&["node", "client"]),
)
.arg(
Arg::new("output")
.long("output")
.takes_value(true)
.help("path-like prefix for the log files (fallbacks to stdout output)"),
),
)
.subcommand(
Command::new("daemon").arg(
Arg::new("config")
.long("config")
.takes_value(true)
.help("config file to load by the daemon"),
),
)
.subcommand(watch::command_definition())
.subcommand(dump::command_definition())
.subcommand(daemon::command_definition())
.arg_required_else_help(true)
.get_matches();

Expand Down
31 changes: 31 additions & 0 deletions src/bin/oura/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,34 @@ pub fn run(args: &ArgMatches) -> Result<(), Error> {

Ok(())
}

/// Creates the clap definition for this sub-command
pub(crate) fn command_definition<'a>() -> clap::Command<'a> {
clap::Command::new("watch")
.arg(clap::Arg::new("socket").required(true))
.arg(
clap::Arg::new("bearer")
.long("bearer")
.takes_value(true)
.possible_values(&["tcp", "unix"]),
)
.arg(clap::Arg::new("magic").long("magic").takes_value(true))
.arg(
clap::Arg::new("since")
.long("since")
.takes_value(true)
.help("point in the chain to start reading from, expects format `slot,hex-hash`"),
)
.arg(
clap::Arg::new("throttle")
.long("throttle")
.takes_value(true)
.help("milliseconds to wait between output lines (for easier reading)"),
)
.arg(
clap::Arg::new("mode")
.long("mode")
.takes_value(true)
.possible_values(&["node", "client"]),
)
}

0 comments on commit c8d888b

Please sign in to comment.