1
Fork 0

Add the arguments subcommand.

This commit is contained in:
Bauke 2023-11-04 15:11:37 +01:00
parent e46047ba46
commit fae18669b2
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 36 additions and 1 deletions

View File

@ -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<String>,
},
}
/// 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<String>,
/// Include a newline at the end of the number.
#[arg(short, long, default_value = "false")]
newline: bool,
},
}

View File

@ -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!(
"{} {}",