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