1
Fork 0

Add the directory subcommand.

This commit is contained in:
Bauke 2023-11-08 14:51:04 +01:00
parent fea8ebc73a
commit b54bc7e655
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 32 additions and 2 deletions

View File

@ -27,6 +27,13 @@ pub enum MainSubcommand {
command: ArgumentsSubcommand, command: ArgumentsSubcommand,
}, },
/// The directory subcommand.
Directory {
/// The directory subcommands.
#[command(subcommand)]
command: DirectorySubcommand,
},
/// The file subcommand. /// The file subcommand.
File { File {
/// The file subcommands. /// The file subcommands.
@ -61,7 +68,19 @@ pub enum ArgumentsSubcommand {
}, },
} }
/// The file subcommands /// The directory subcommands.
#[derive(Debug, Subcommand)]
pub enum DirectorySubcommand {
/// Check whether a directory exists, if the directory does not exist the exit
/// code will be 1.
Exists {
/// The path to a potential directory.
#[arg()]
directory: PathBuf,
},
}
/// The file subcommands.
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
pub enum FileSubcommand { pub enum FileSubcommand {
/// Check whether a file exists, if the file does not exist the exit code will /// Check whether a file exists, if the file does not exist the exit code will

View File

@ -3,7 +3,8 @@
use { use {
crate::{ crate::{
cli::{ cli::{
ArgumentsSubcommand, Cli, FileSubcommand, MainSubcommand::*, Parser, ArgumentsSubcommand, Cli, DirectorySubcommand, FileSubcommand,
MainSubcommand::*, Parser,
}, },
logging::append_line_to_file, logging::append_line_to_file,
}, },
@ -29,6 +30,16 @@ pub fn run() {
} }
}, },
Directory {
command: directory_subcommand,
} => match directory_subcommand {
DirectorySubcommand::Exists { directory } => {
if !(directory.exists() && directory.is_dir()) {
std::process::exit(1);
}
}
},
File { File {
command: file_subcommand, command: file_subcommand,
} => match file_subcommand { } => match file_subcommand {