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