Add the directory subcommand.
This commit is contained in:
parent
fea8ebc73a
commit
b54bc7e655
|
@ -27,6 +27,13 @@ pub enum MainSubcommand {
|
|||
command: ArgumentsSubcommand,
|
||||
},
|
||||
|
||||
/// The directory subcommand.
|
||||
Directory {
|
||||
/// The directory subcommands.
|
||||
#[command(subcommand)]
|
||||
command: DirectorySubcommand,
|
||||
},
|
||||
|
||||
/// The file subcommand.
|
||||
File {
|
||||
/// 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)]
|
||||
pub enum FileSubcommand {
|
||||
/// Check whether a file exists, if the file does not exist the exit code will
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
use {
|
||||
crate::{
|
||||
cli::{
|
||||
ArgumentsSubcommand, Cli, FileSubcommand, MainSubcommand::*, Parser,
|
||||
ArgumentsSubcommand, Cli, DirectorySubcommand, FileSubcommand,
|
||||
MainSubcommand::*, Parser,
|
||||
},
|
||||
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 {
|
||||
command: file_subcommand,
|
||||
} => match file_subcommand {
|
||||
|
|
Loading…
Reference in New Issue