1
Fork 0

Add the file subcommand.

This commit is contained in:
Bauke 2023-11-05 12:18:45 +01:00
parent fdbb8c99df
commit 6dc3aed5e8
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 33 additions and 1 deletions

View File

@ -3,6 +3,7 @@
pub use { pub use {
crate::cli::run::run, crate::cli::run::run,
clap::{Parser, Subcommand}, clap::{Parser, Subcommand},
std::path::PathBuf,
}; };
mod run; mod run;
@ -26,6 +27,13 @@ pub enum MainSubcommand {
command: ArgumentsSubcommand, command: ArgumentsSubcommand,
}, },
/// The file subcommand.
File {
/// The file subcommands.
#[command(subcommand)]
command: FileSubcommand,
},
/// The log subcommand. /// The log subcommand.
Log { Log {
/// The data to log. /// The data to log.
@ -52,3 +60,15 @@ pub enum ArgumentsSubcommand {
newline: bool, 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,
},
}

View File

@ -2,7 +2,9 @@
use { use {
crate::{ crate::{
cli::{ArgumentsSubcommand, Cli, MainSubcommand::*, Parser}, cli::{
ArgumentsSubcommand, Cli, FileSubcommand, MainSubcommand::*, Parser,
},
logging::append_line_to_file, logging::append_line_to_file,
}, },
chrono::{SecondsFormat, Utc}, 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 } => { Log { data_to_log, file } => {
let log_line = format!( let log_line = format!(
"{} {}", "{} {}",