2022-10-28 17:39:15 +00:00
|
|
|
//! [`clap`] Derive structs.
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-01-18 13:37:02 +00:00
|
|
|
use {
|
|
|
|
clap::{Args as Arguments, Parser, Subcommand},
|
|
|
|
hooked_config::NoiseLevel,
|
|
|
|
};
|
2022-10-28 17:39:15 +00:00
|
|
|
|
2022-11-06 17:44:23 +00:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
mod cli_reference;
|
2022-11-04 17:09:15 +00:00
|
|
|
mod install;
|
2022-10-30 20:14:12 +00:00
|
|
|
mod run;
|
2022-11-04 17:09:15 +00:00
|
|
|
mod uninstall;
|
2022-10-30 20:14:12 +00:00
|
|
|
|
2022-11-06 17:44:23 +00:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
pub use cli_reference::hooked_cli_reference;
|
2022-11-04 17:09:15 +00:00
|
|
|
pub use install::hooked_install;
|
2022-10-30 20:14:12 +00:00
|
|
|
pub use run::hooked_run;
|
2022-11-04 17:09:15 +00:00
|
|
|
pub use uninstall::hooked_uninstall;
|
2022-10-30 20:14:12 +00:00
|
|
|
|
2022-10-28 17:39:15 +00:00
|
|
|
/// CLI arguments struct using [`clap::Parser`].
|
|
|
|
#[derive(Debug, Parser)]
|
|
|
|
#[clap(about, author, version)]
|
|
|
|
#[clap(propagate_version = true)]
|
|
|
|
pub struct Args {
|
|
|
|
/// The CLI subcommand.
|
|
|
|
#[clap(subcommand)]
|
|
|
|
pub command: MainSubcommands,
|
|
|
|
|
|
|
|
/// Path to a Hooked configuration.
|
|
|
|
#[clap(short, long, global = true, default_value = "Hooked.toml")]
|
|
|
|
pub config: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Main CLI subcommands.
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
pub enum MainSubcommands {
|
|
|
|
/// Install Hooked into ".git/hooks".
|
2022-11-04 16:54:05 +00:00
|
|
|
Install(InstallArgs),
|
2022-10-28 18:24:07 +00:00
|
|
|
|
|
|
|
/// Remove installed hooks.
|
2022-11-04 16:54:05 +00:00
|
|
|
Uninstall(UninstallArgs),
|
2022-10-30 20:14:12 +00:00
|
|
|
|
|
|
|
/// Manually run hooks.
|
2022-11-04 16:54:05 +00:00
|
|
|
Run(RunArgs),
|
2022-11-06 17:44:23 +00:00
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
/// Generate the CLI reference file for the mdBook.
|
|
|
|
CliReference(CliReferenceArgs),
|
2022-11-04 16:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The `install` subcommand arguments.
|
|
|
|
#[derive(Debug, Arguments)]
|
|
|
|
pub struct InstallArgs {
|
|
|
|
/// Overwrite existing files.
|
|
|
|
#[clap(long)]
|
|
|
|
pub overwrite: bool,
|
2024-01-24 17:27:32 +00:00
|
|
|
|
|
|
|
/// Don't output any information.
|
|
|
|
#[clap(long)]
|
|
|
|
pub silent: bool,
|
2022-11-04 16:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The `uninstall` subcommand arguments.
|
|
|
|
#[derive(Debug, Arguments)]
|
|
|
|
pub struct UninstallArgs {
|
|
|
|
/// Remove hooks not installed by Hooked.
|
|
|
|
#[clap(long)]
|
|
|
|
pub all: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The `run` subcommand arguments.
|
|
|
|
#[derive(Debug, Arguments)]
|
|
|
|
pub struct RunArgs {
|
|
|
|
/// The hook type to run.
|
|
|
|
#[clap(value_parser = crate::HOOK_TYPES)]
|
|
|
|
pub hook_type: String,
|
2024-01-18 13:37:02 +00:00
|
|
|
|
|
|
|
/// The noise level to override for all hooks.
|
|
|
|
#[clap(long)]
|
|
|
|
pub noise_level: Option<NoiseLevel>,
|
2022-10-28 17:39:15 +00:00
|
|
|
}
|
2022-11-06 17:44:23 +00:00
|
|
|
|
|
|
|
/// The `cli-reference` subcommand arguments.
|
|
|
|
#[derive(Debug, Arguments)]
|
|
|
|
pub struct CliReferenceArgs {
|
|
|
|
/// Path where the CLI reference file should be generated.
|
|
|
|
#[clap(short, long, default_value = "hooked-book/source/")]
|
|
|
|
pub output: PathBuf,
|
|
|
|
}
|