From 1a20348bf1384a7d22ce671d8feb54cca83eed5b Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 15 Nov 2023 17:43:17 +0100 Subject: [PATCH] Add the date subcommand. --- source/cli/mod.rs | 18 ++++++++++++++++++ source/cli/run.rs | 12 ++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/cli/mod.rs b/source/cli/mod.rs index ab2590b..fcdc333 100644 --- a/source/cli/mod.rs +++ b/source/cli/mod.rs @@ -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 { diff --git a/source/cli/run.rs b/source/cli/run.rs index ee9258f..0bc5aa8 100644 --- a/source/cli/run.rs +++ b/source/cli/run.rs @@ -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 {