From 733813e71972811ed14f846cda644936cba5655e Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 2 Dec 2021 22:42:20 -0600 Subject: [PATCH] Add subcommands to main command The main command now supports subcommands for the various puzzles. The first subcommand is `sonar`, for working with the sonar data from the Day 1 puzzles. --- src/main.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0ff668e..262a8a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,22 @@ use argh::FromArgs; mod sonar; #[derive(FromArgs)] -/// Elvish Submarine Sonar Tracker +/// Elvish Submarine Control struct Arguments { + #[argh(subcommand)] + command: SubCommand, +} + +#[derive(FromArgs)] +#[argh(subcommand)] +enum SubCommand { + Sonar(SonarTracker), +} + +#[derive(FromArgs)] +/// sonar data reader +#[argh(subcommand, name = "sonar")] +struct SonarTracker { /// path to input data file #[argh(positional)] input: String, @@ -18,7 +32,11 @@ struct Arguments { fn main() -> io::Result<()> { let args: Arguments = argh::from_env(); - let count_incr = sonar::count_increases(&args.input, args.window)?; - println!("number of increases: {}", count_incr); + match args.command { + SubCommand::Sonar(args) => { + let count_incr = sonar::count_increases(&args.input, args.window)?; + println!("number of increases: {}", count_incr); + } + } Ok(()) }