diff --git a/source/cli/mod.rs b/source/cli/mod.rs index e511214..dd235cb 100644 --- a/source/cli/mod.rs +++ b/source/cli/mod.rs @@ -3,6 +3,7 @@ pub use { crate::cli::run::run, clap::{Parser, Subcommand}, + std::path::PathBuf, }; mod run; @@ -26,6 +27,13 @@ pub enum MainSubcommand { command: ArgumentsSubcommand, }, + /// The file subcommand. + File { + /// The file subcommands. + #[command(subcommand)] + command: FileSubcommand, + }, + /// The log subcommand. Log { /// The data to log. @@ -52,3 +60,15 @@ pub enum ArgumentsSubcommand { newline: bool, }, } + +/// The file subcommands +#[derive(Debug, Subcommand)] +pub enum FileSubcommand { + /// Check whether a file exists, if the file does not exist the exit code will + /// be 1. + Exists { + /// The path to a potential file. + #[arg()] + file: PathBuf, + }, +} diff --git a/source/cli/run.rs b/source/cli/run.rs index 06d6d7f..10f0508 100644 --- a/source/cli/run.rs +++ b/source/cli/run.rs @@ -2,7 +2,9 @@ use { crate::{ - cli::{ArgumentsSubcommand, Cli, MainSubcommand::*, Parser}, + cli::{ + ArgumentsSubcommand, Cli, FileSubcommand, MainSubcommand::*, Parser, + }, logging::append_line_to_file, }, chrono::{SecondsFormat, Utc}, @@ -26,6 +28,16 @@ pub fn run() { } }, + File { + command: file_subcommand, + } => match file_subcommand { + FileSubcommand::Exists { file } => { + if !file.exists() { + std::process::exit(1); + } + } + }, + Log { data_to_log, file } => { let log_line = format!( "{} {}",