1
Fork 0

Add the date subcommand.

This commit is contained in:
Bauke 2023-11-15 17:43:17 +01:00
parent 8278ffbcbd
commit 1a20348bf1
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 28 additions and 2 deletions

View File

@ -27,6 +27,13 @@ pub enum MainSubcommand {
command: ArgumentsSubcommand,
},
/// The date subcommand.
Date {
/// The date subcommands.
#[command(subcommand)]
command: DateSubcommand,
},
/// The directory subcommand.
Directory {
/// The directory subcommands.
@ -75,6 +82,17 @@ pub enum ArgumentsSubcommand {
},
}
/// The date subcommands.
#[derive(Debug, Subcommand)]
pub enum DateSubcommand {
/// Gets the current date.
Now {
/// The format string for the date, defaults to ISO 8601.
#[arg(short, long, default_value = "%FT%T%z")]
format: String,
},
}
/// The directory subcommands.
#[derive(Debug, Subcommand)]
pub enum DirectorySubcommand {

View File

@ -3,8 +3,8 @@
use {
crate::{
cli::{
ArgumentsSubcommand, Cli, DirectorySubcommand, FileSubcommand,
MainSubcommand::*, MatchSubcommand, Parser,
ArgumentsSubcommand, Cli, DateSubcommand, DirectorySubcommand,
FileSubcommand, MainSubcommand::*, MatchSubcommand, Parser,
},
logging::append_line_to_file,
},
@ -30,6 +30,14 @@ pub fn run() {
}
},
Date {
command: date_subcommand,
} => match date_subcommand {
DateSubcommand::Now { format } => {
print!("{}", Local::now().format(&format));
}
},
Directory {
command: directory_subcommand,
} => match directory_subcommand {