From 1c6b18c0250e3b724ec49efc83f3f2b5bdf08b85 Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Sun, 10 Nov 2024 03:43:09 +0000 Subject: [PATCH] rename args, tests pass --- bin/src/commands/build.rs | 10 ++++++--- bin/src/commands/check.rs | 5 ++++- bin/src/commands/dev.rs | 10 ++++++--- bin/src/commands/launch/mod.rs | 10 ++++++--- bin/src/commands/localization/coverage.rs | 5 +++-- bin/src/commands/localization/mod.rs | 7 ++++-- bin/src/commands/localization/sort.rs | 5 +++-- bin/src/commands/release.rs | 10 ++++++--- bin/src/commands/script.rs | 3 +++ bin/src/commands/utils.rs | 3 +++ bin/src/commands/wiki.rs | 3 +++ bin/src/lib.rs | 26 ++++++++++++++--------- bin/src/utils/config/inspect.rs | 3 ++- bin/src/utils/config/mod.rs | 2 +- bin/src/utils/paa/convert.rs | 4 ++-- bin/src/utils/paa/inspect.rs | 2 +- bin/src/utils/paa/mod.rs | 4 ++-- bin/src/utils/pbo/extract.rs | 4 ++-- bin/src/utils/pbo/inspect.rs | 2 +- bin/src/utils/pbo/mod.rs | 6 +++--- bin/src/utils/pbo/unpack.rs | 4 ++-- bin/src/utils/sqf/case.rs | 4 ++-- bin/src/utils/sqf/mod.rs | 2 +- 23 files changed, 87 insertions(+), 47 deletions(-) diff --git a/bin/src/commands/build.rs b/bin/src/commands/build.rs index f7f78d6a..1c8059d9 100644 --- a/bin/src/commands/build.rs +++ b/bin/src/commands/build.rs @@ -14,14 +14,18 @@ use super::global_modules; /// Build your project in release mode for testing, without signing for full release. pub struct Command { #[clap(flatten)] - build: Args, + build: BuildArgs, #[clap(flatten)] just: super::JustArgs, + + #[clap(flatten)] + global: crate::GlobalArgs, } #[derive(clap::Args)] -pub struct Args { +#[allow(clippy::module_name_repetitions)] +pub struct BuildArgs { #[arg(long, action = clap::ArgAction::SetTrue)] /// Do not binarize the project no_bin: bool, @@ -66,7 +70,7 @@ pub fn execute(cmd: &Command) -> Result { } #[must_use] -pub fn executor(ctx: Context, args: &Args) -> Executor { +pub fn executor(ctx: Context, args: &BuildArgs) -> Executor { let mut executor = Executor::new(ctx); global_modules(&mut executor); diff --git a/bin/src/commands/check.rs b/bin/src/commands/check.rs index 99555faa..4460c8fd 100644 --- a/bin/src/commands/check.rs +++ b/bin/src/commands/check.rs @@ -9,7 +9,10 @@ use crate::{ #[derive(clap::Parser)] /// Check the project for errors -pub struct Command {} +pub struct Command { + #[clap(flatten)] + global: crate::GlobalArgs, +} /// Execute the dev command /// diff --git a/bin/src/commands/dev.rs b/bin/src/commands/dev.rs index ec778367..04b1147d 100644 --- a/bin/src/commands/dev.rs +++ b/bin/src/commands/dev.rs @@ -18,14 +18,18 @@ use super::JustArgs; /// It is built without binarization of .p3d and .rtm files. pub struct Command { #[clap(flatten)] - dev: Args, + dev: DevArgs, #[clap(flatten)] just: JustArgs, + + #[clap(flatten)] + global: crate::GlobalArgs, } #[derive(clap::Args)] -pub struct Args { +#[allow(clippy::module_name_repetitions)] +pub struct DevArgs { #[arg(long, short, action = clap::ArgAction::SetTrue)] /// Use BI's binarize on supported files binarize: bool, @@ -54,7 +58,7 @@ pub fn execute(cmd: &Command, launch_optionals: &[String]) -> Result]` configurations config: Option>, diff --git a/bin/src/commands/localization/coverage.rs b/bin/src/commands/localization/coverage.rs index 4a89a861..68dc184d 100644 --- a/bin/src/commands/localization/coverage.rs +++ b/bin/src/commands/localization/coverage.rs @@ -7,7 +7,8 @@ use tabled::{settings::Style, Table, Tabled}; use crate::{context::Context, report::Report, Error, TableFormat}; #[derive(clap::Args)] -pub struct Args { +#[allow(clippy::module_name_repetitions)] +pub struct LocalizationCoverageArgs { #[arg(long, default_value = "ascii")] /// Output format format: TableFormat, @@ -78,7 +79,7 @@ struct Entry { missing: MissingAddons, } -pub fn coverage(args: &Args) -> Result { +pub fn coverage(args: &LocalizationCoverageArgs) -> Result { let ctx = Context::new(None, crate::context::PreservePrevious::Remove, true)?; let mut global = Totals::default(); diff --git a/bin/src/commands/localization/mod.rs b/bin/src/commands/localization/mod.rs index de3e63c3..2e69e7d2 100644 --- a/bin/src/commands/localization/mod.rs +++ b/bin/src/commands/localization/mod.rs @@ -9,14 +9,17 @@ mod sort; pub struct Command { #[command(subcommand)] commands: Subcommands, + + #[clap(flatten)] + global: crate::GlobalArgs, } #[derive(clap::Subcommand)] enum Subcommands { /// Generate a coverage report - Coverage(coverage::Args), + Coverage(coverage::LocalizationCoverageArgs), /// Sort the stringtables - Sort(sort::Args), + Sort(sort::LocalizationSortArgs), } /// Execute the localization command diff --git a/bin/src/commands/localization/sort.rs b/bin/src/commands/localization/sort.rs index 9a8a9b04..0e46bdc8 100644 --- a/bin/src/commands/localization/sort.rs +++ b/bin/src/commands/localization/sort.rs @@ -5,13 +5,14 @@ use hemtt_stringtable::Project; use crate::{context::Context, report::Report, Error}; #[derive(clap::Args)] -pub struct Args { +#[allow(clippy::module_name_repetitions)] +pub struct LocalizationSortArgs { #[arg(long)] /// Only sort the languages within keys only_lang: bool, } -pub fn sort(args: &Args) -> Result { +pub fn sort(args: &LocalizationSortArgs) -> Result { let ctx = Context::new(None, crate::context::PreservePrevious::Remove, true)?; for root in ["addons", "optionals"] { diff --git a/bin/src/commands/release.rs b/bin/src/commands/release.rs index 73529b57..744d804c 100644 --- a/bin/src/commands/release.rs +++ b/bin/src/commands/release.rs @@ -8,14 +8,18 @@ use super::build; /// Build your project for full release, with signing and archiving. pub struct Command { #[clap(flatten)] - build: build::Args, + build: build::BuildArgs, #[clap(flatten)] - release: Args, + release: ReleaseArgs, + + #[clap(flatten)] + global: crate::GlobalArgs, } #[derive(clap::Args)] -pub struct Args { +#[allow(clippy::module_name_repetitions)] +pub struct ReleaseArgs { #[arg(long, action = clap::ArgAction::SetTrue)] /// Do not sign the PBOs no_sign: bool, diff --git a/bin/src/commands/script.rs b/bin/src/commands/script.rs index 9e677f55..05d5dd2f 100644 --- a/bin/src/commands/script.rs +++ b/bin/src/commands/script.rs @@ -9,6 +9,9 @@ use crate::{context::Context, error::Error, modules::Hooks, report::Report}; pub struct Command { #[clap(name = "name")] name: String, + + #[clap(flatten)] + global: crate::GlobalArgs, } /// Execute the script command diff --git a/bin/src/commands/utils.rs b/bin/src/commands/utils.rs index 77764164..dc4ce79f 100644 --- a/bin/src/commands/utils.rs +++ b/bin/src/commands/utils.rs @@ -6,6 +6,9 @@ use crate::{report::Report, utils, Error}; pub struct Command { #[command(subcommand)] commands: Subcommands, + + #[clap(flatten)] + global: crate::GlobalArgs, } #[derive(clap::Subcommand)] diff --git a/bin/src/commands/wiki.rs b/bin/src/commands/wiki.rs index f7ad52f4..052aff99 100644 --- a/bin/src/commands/wiki.rs +++ b/bin/src/commands/wiki.rs @@ -8,6 +8,9 @@ use crate::{error::Error, report::Report}; pub struct Command { #[command(subcommand)] commands: Subcommands, + + #[clap(flatten)] + global: crate::GlobalArgs, } #[derive(clap::Subcommand)] diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 56e2af10..4f8e2d5e 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -24,18 +24,24 @@ pub struct Cli { #[command(subcommand)] command: Option, - #[arg(long, short)] + #[clap(flatten)] + global: GlobalArgs, +} + +#[derive(clap::Args)] +pub struct GlobalArgs { + #[arg(global = true, long, short)] /// Number of threads, defaults to # of CPUs threads: Option, - #[arg(short, action = clap::ArgAction::Count)] + #[arg(global = true, short, action = clap::ArgAction::Count)] /// Verbosity level verbosity: u8, #[cfg(debug_assertions)] - #[arg(long, short)] + #[arg(global = true, long)] /// Directory to run in dir: Option, #[cfg(debug_assertions)] - #[arg(long, short, hide = true)] + #[arg(global = true, long, hide = true, action = clap::ArgAction::SetTrue)] /// we are in a test in_test: bool, } @@ -67,7 +73,7 @@ enum Commands { pub fn execute(cli: &Cli) -> Result<(), Error> { // check for -v with no command and show version if cli.command.is_none() { - if cli.verbosity > 0 { + if cli.global.verbosity > 0 { println!("{} {}", env!("CARGO_PKG_NAME"), env!("HEMTT_VERSION")); return Ok(()); } @@ -77,20 +83,20 @@ pub fn execute(cli: &Cli) -> Result<(), Error> { std::process::exit(1); } - if !matches!(cli.command, Some(Commands::Value(_))) { + if !cfg!(debug_assertions) && !matches!(cli.command, Some(Commands::Value(_))) { logging::init( - cli.verbosity, + cli.global.verbosity, !matches!(cli.command, Some(Commands::Utils(_))), ); } #[cfg(debug_assertions)] - let in_test = cli.in_test; + let in_test = cli.global.in_test; #[cfg(not(debug_assertions))] let in_test = false; #[cfg(debug_assertions)] - if let Some(dir) = &cli.dir { + if let Some(dir) = &cli.global.dir { std::env::set_current_dir(dir).expect("Failed to set current directory"); } @@ -119,7 +125,7 @@ pub fn execute(cli: &Cli) -> Result<(), Error> { trace!("args: {:#?}", std::env::args().collect::>()); - if let Some(threads) = cli.threads { + if let Some(threads) = cli.global.threads { debug!("Using custom thread count: {threads}"); if let Err(e) = rayon::ThreadPoolBuilder::new() .num_threads(threads) diff --git a/bin/src/utils/config/inspect.rs b/bin/src/utils/config/inspect.rs index a405c5e3..26be1d70 100644 --- a/bin/src/utils/config/inspect.rs +++ b/bin/src/utils/config/inspect.rs @@ -9,7 +9,8 @@ use hemtt_workspace::{ }; #[derive(clap::Args)] -pub struct Args { +#[allow(clippy::module_name_repetitions)] +pub struct InspectArgs { /// Config to inspect pub(crate) config: String, } diff --git a/bin/src/utils/config/mod.rs b/bin/src/utils/config/mod.rs index 0c5997d9..63f121b9 100644 --- a/bin/src/utils/config/mod.rs +++ b/bin/src/utils/config/mod.rs @@ -17,7 +17,7 @@ pub struct Command { #[derive(clap::Subcommand)] enum Subcommands { /// Inspect a config file - Inspect(inspect::Args), + Inspect(inspect::InspectArgs), } /// Execute the config command diff --git a/bin/src/utils/paa/convert.rs b/bin/src/utils/paa/convert.rs index 1aa9ddb8..321437be 100644 --- a/bin/src/utils/paa/convert.rs +++ b/bin/src/utils/paa/convert.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use crate::Error; #[derive(clap::Args)] -pub struct Args { +pub struct PaaConvertArgs { /// PAA to convert paa: String, /// Where to save the file @@ -14,7 +14,7 @@ pub struct Args { /// /// # Errors /// [`Error`] depending on the modules -pub fn execute(args: &Args) -> Result<(), Error> { +pub fn execute(args: &PaaConvertArgs) -> Result<(), Error> { let paa = PathBuf::from(&args.paa); let output = PathBuf::from(&args.output); if output.exists() { diff --git a/bin/src/utils/paa/inspect.rs b/bin/src/utils/paa/inspect.rs index b9081a9e..77dacc67 100644 --- a/bin/src/utils/paa/inspect.rs +++ b/bin/src/utils/paa/inspect.rs @@ -9,7 +9,7 @@ use tabled::{ use crate::{Error, TableFormat}; #[derive(clap::Args)] -pub struct Args { +pub struct PaaInspectArgs { /// PAA to inspect pub(crate) paa: String, #[clap(long, default_value = "ascii")] diff --git a/bin/src/utils/paa/mod.rs b/bin/src/utils/paa/mod.rs index 79a71971..cd70d6ae 100644 --- a/bin/src/utils/paa/mod.rs +++ b/bin/src/utils/paa/mod.rs @@ -17,8 +17,8 @@ pub struct Command { #[derive(clap::Subcommand)] enum Subcommands { - Convert(convert::Args), - Inspect(inspect::Args), + Convert(convert::PaaConvertArgs), + Inspect(inspect::PaaInspectArgs), } /// Execute the paa command diff --git a/bin/src/utils/pbo/extract.rs b/bin/src/utils/pbo/extract.rs index fb80ce78..72312c06 100644 --- a/bin/src/utils/pbo/extract.rs +++ b/bin/src/utils/pbo/extract.rs @@ -6,7 +6,7 @@ use crate::Error; #[derive(clap::Args)] /// Arguments for the extract command -pub struct Args { +pub struct PboExtractArgs { /// PBO file to extract from pbo: String, /// File to extract @@ -19,7 +19,7 @@ pub struct Args { /// /// # Errors /// [`Error`] depending on the modules -pub fn execute(args: &Args) -> Result<(), Error> { +pub fn execute(args: &PboExtractArgs) -> Result<(), Error> { let path = PathBuf::from(&args.pbo); let mut pbo = ReadablePbo::from(File::open(path)?)?; let Some(mut file) = pbo.file(&args.file)? else { diff --git a/bin/src/utils/pbo/inspect.rs b/bin/src/utils/pbo/inspect.rs index 5c073ce6..d7a6e6ad 100644 --- a/bin/src/utils/pbo/inspect.rs +++ b/bin/src/utils/pbo/inspect.rs @@ -10,7 +10,7 @@ use tabled::{ use crate::{Error, TableFormat}; #[derive(clap::Args)] -pub struct Args { +pub struct PboInspectArgs { /// PBO to inspect pub(crate) pbo: String, #[clap(long, default_value = "ascii")] diff --git a/bin/src/utils/pbo/mod.rs b/bin/src/utils/pbo/mod.rs index a3b117b5..fd3c1ed7 100644 --- a/bin/src/utils/pbo/mod.rs +++ b/bin/src/utils/pbo/mod.rs @@ -19,11 +19,11 @@ pub struct Command { #[derive(clap::Subcommand)] enum Subcommands { /// Extract a file from a PBO - Extract(extract::Args), + Extract(extract::PboExtractArgs), /// Inspect a PBO file - Inspect(inspect::Args), + Inspect(inspect::PboInspectArgs), /// Unpack a PBO file - Unpack(unpack::Args), + Unpack(unpack::PboUnpackArgs), } /// Execute the pbo command diff --git a/bin/src/utils/pbo/unpack.rs b/bin/src/utils/pbo/unpack.rs index 49e63a57..4c11063b 100644 --- a/bin/src/utils/pbo/unpack.rs +++ b/bin/src/utils/pbo/unpack.rs @@ -9,7 +9,7 @@ use hemtt_pbo::ReadablePbo; use crate::Error; #[derive(clap::Args)] -pub struct Args { +pub struct PboUnpackArgs { /// PBO file to unpack pbo: String, /// Directory to unpack to @@ -20,7 +20,7 @@ pub struct Args { /// /// # Errors /// [`Error`] depending on the modules -pub fn execute(args: &Args) -> Result<(), Error> { +pub fn execute(args: &PboUnpackArgs) -> Result<(), Error> { let path = PathBuf::from(&args.pbo); let mut pbo = ReadablePbo::from(File::open(path)?)?; let output = PathBuf::from(&args.output); diff --git a/bin/src/utils/sqf/case.rs b/bin/src/utils/sqf/case.rs index c73db329..5d202426 100644 --- a/bin/src/utils/sqf/case.rs +++ b/bin/src/utils/sqf/case.rs @@ -8,7 +8,7 @@ use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use crate::Error; #[derive(clap::Args)] -pub struct Args { +pub struct SqfCaseArgs { path: String, } @@ -16,7 +16,7 @@ pub struct Args { /// /// # Errors /// [`Error`] depending on the modules -pub fn execute(args: &Args) -> Result<(), Error> { +pub fn execute(args: &SqfCaseArgs) -> Result<(), Error> { let path = PathBuf::from(&args.path); if path.is_dir() { let count = Arc::new(AtomicUsize::new(0)); diff --git a/bin/src/utils/sqf/mod.rs b/bin/src/utils/sqf/mod.rs index c9cff3f2..e699da6e 100644 --- a/bin/src/utils/sqf/mod.rs +++ b/bin/src/utils/sqf/mod.rs @@ -13,7 +13,7 @@ pub struct Command { #[derive(clap::Subcommand)] enum Subcommands { /// Convert case - Case(case::Args), + Case(case::SqfCaseArgs), } /// Execute the paa command