2023-10-31 15:58:35 +00:00
|
|
|
//! The CLI definitions.
|
|
|
|
|
2023-11-01 16:56:32 +00:00
|
|
|
pub use {
|
|
|
|
crate::cli::run::run,
|
|
|
|
clap::{Parser, Subcommand},
|
2023-11-05 11:18:45 +00:00
|
|
|
std::path::PathBuf,
|
2023-11-01 16:56:32 +00:00
|
|
|
};
|
2023-10-31 13:51:57 +00:00
|
|
|
|
|
|
|
mod run;
|
|
|
|
|
2023-10-31 15:58:35 +00:00
|
|
|
/// The main CLI command.
|
2023-10-31 13:51:57 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2023-11-01 16:56:32 +00:00
|
|
|
#[command(about, author, version, propagate_version = true)]
|
|
|
|
pub struct Cli {
|
|
|
|
/// The main CLI subcommand.
|
|
|
|
#[command(subcommand)]
|
|
|
|
pub command: MainSubcommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The main subcommands.
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
pub enum MainSubcommand {
|
2023-11-04 14:11:37 +00:00
|
|
|
/// The arguments subcommand.
|
|
|
|
Arguments {
|
|
|
|
/// The arguments subcommands.
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: ArgumentsSubcommand,
|
|
|
|
},
|
|
|
|
|
2023-11-08 13:51:04 +00:00
|
|
|
/// The directory subcommand.
|
|
|
|
Directory {
|
|
|
|
/// The directory subcommands.
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: DirectorySubcommand,
|
|
|
|
},
|
|
|
|
|
2023-11-05 11:18:45 +00:00
|
|
|
/// The file subcommand.
|
|
|
|
File {
|
|
|
|
/// The file subcommands.
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: FileSubcommand,
|
|
|
|
},
|
|
|
|
|
2023-11-01 16:56:32 +00:00
|
|
|
/// The log subcommand.
|
|
|
|
Log {
|
|
|
|
/// The data to log.
|
|
|
|
#[arg(last = true)]
|
|
|
|
data_to_log: Vec<String>,
|
2023-11-04 14:35:54 +00:00
|
|
|
|
|
|
|
/// The file to log to, it will be created if it doesn't exist.
|
|
|
|
#[arg(short, long, default_value = "bautils.log")]
|
|
|
|
file: String,
|
2023-11-01 16:56:32 +00:00
|
|
|
},
|
|
|
|
}
|
2023-11-04 14:11:37 +00:00
|
|
|
|
|
|
|
/// The arguments subcommands.
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
pub enum ArgumentsSubcommand {
|
|
|
|
/// Print the count of provided arguments.
|
|
|
|
Count {
|
|
|
|
/// The arguments to print the count of.
|
|
|
|
#[arg(last = true)]
|
|
|
|
arguments: Vec<String>,
|
|
|
|
|
|
|
|
/// Include a newline at the end of the number.
|
|
|
|
#[arg(short, long, default_value = "false")]
|
|
|
|
newline: bool,
|
|
|
|
},
|
|
|
|
}
|
2023-11-05 11:18:45 +00:00
|
|
|
|
2023-11-08 13:51:04 +00:00
|
|
|
/// 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.
|
2023-11-05 11:18:45 +00:00
|
|
|
#[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,
|
|
|
|
},
|
2023-11-06 17:54:33 +00:00
|
|
|
|
|
|
|
/// Extract parts of a file.
|
|
|
|
Parts {
|
|
|
|
/// Print the base name of the file (without the extension).
|
|
|
|
#[arg(long, group = "part-to-print", default_value = "false")]
|
|
|
|
basename: bool,
|
|
|
|
|
|
|
|
/// Print the directory the file is in.
|
|
|
|
#[arg(long, group = "part-to-print", default_value = "false")]
|
|
|
|
directory: bool,
|
|
|
|
|
|
|
|
/// Print the file extension (without the leading dot).
|
|
|
|
#[arg(long, group = "part-to-print", default_value = "false")]
|
|
|
|
extension: bool,
|
|
|
|
|
|
|
|
/// The file to include parts from.
|
|
|
|
#[arg()]
|
|
|
|
file: PathBuf,
|
|
|
|
},
|
2023-11-05 11:18:45 +00:00
|
|
|
}
|