From fae18669b26feb6be54a0b9ca4b4c4df66d31ce2 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 4 Nov 2023 15:11:37 +0100 Subject: [PATCH] Add the arguments subcommand. --- source/cli/mod.rs | 22 ++++++++++++++++++++++ source/cli/run.rs | 15 ++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/source/cli/mod.rs b/source/cli/mod.rs index b2ca918..740d71a 100644 --- a/source/cli/mod.rs +++ b/source/cli/mod.rs @@ -19,6 +19,13 @@ pub struct Cli { /// The main subcommands. #[derive(Debug, Subcommand)] pub enum MainSubcommand { + /// The arguments subcommand. + Arguments { + /// The arguments subcommands. + #[command(subcommand)] + command: ArgumentsSubcommand, + }, + /// The log subcommand. Log { /// The data to log. @@ -26,3 +33,18 @@ pub enum MainSubcommand { data_to_log: Vec, }, } + +/// The arguments subcommands. +#[derive(Debug, Subcommand)] +pub enum ArgumentsSubcommand { + /// Print the count of provided arguments. + Count { + /// The arguments to print the count of. + #[arg(last = true)] + arguments: Vec, + + /// Include a newline at the end of the number. + #[arg(short, long, default_value = "false")] + newline: bool, + }, +} diff --git a/source/cli/run.rs b/source/cli/run.rs index e388a44..77bfc4d 100644 --- a/source/cli/run.rs +++ b/source/cli/run.rs @@ -2,7 +2,7 @@ use { crate::{ - cli::{Cli, MainSubcommand::*, Parser}, + cli::{ArgumentsSubcommand, Cli, MainSubcommand::*, Parser}, logging::append_line_to_file, }, chrono::{SecondsFormat, Utc}, @@ -13,6 +13,19 @@ pub fn run() { let cli = Cli::parse(); match cli.command { + Arguments { + command: arguments_subcommand, + } => match arguments_subcommand { + ArgumentsSubcommand::Count { arguments, newline } => { + let mut count = format!("{}", arguments.len()); + if newline { + count.push('\n'); + } + + print!("{}", count); + } + }, + Log { data_to_log } => { let log_line = format!( "{} {}",