Add the arguments subcommand.
This commit is contained in:
parent
e46047ba46
commit
fae18669b2
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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!(
|
||||
"{} {}",
|
||||
|
|
Loading…
Reference in New Issue