Skip to content

Commit

Permalink
use clap derive, more table formats
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Nov 9, 2024
1 parent 7f055cd commit 052ce69
Show file tree
Hide file tree
Showing 37 changed files with 790 additions and 780 deletions.
104 changes: 88 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ serde_json = "1.0.132"
sha-1 = "0.10.1"
strsim = "0.11.1"
supports-hyperlinks = "3.0.0"
tabled = "0.16.0"
terminal-link = "0.1.0"
thiserror = "1.0.65"
toml = "0.8.19"
Expand Down
4 changes: 2 additions & 2 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ hemtt-stringtable = { path = "../libs/stringtable", version = "1.0.0" }
hemtt-workspace = { path = "../libs/workspace", version = "1.0.0" }

arma3-wiki = { workspace = true }
clap = { workspace = true }
clap = { workspace = true, features = ["derive"] }
dialoguer = "0.11.0"
dirs = { workspace = true }
fs_extra = "1.3.0"
Expand All @@ -49,7 +49,7 @@ semver = "1.0.23"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
supports-hyperlinks = { workspace = true }
term-table = "1.4.0"
tabled = { workspace = true }
terminal-link = { workspace = true }
time = { version = "0.3.36", features = ["formatting"] }
tracing = { workspace = true }
Expand Down
11 changes: 4 additions & 7 deletions bin/src/commands/book.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use clap::{ArgMatches, Command};

use crate::{report::Report, Error};

#[must_use]
pub fn cli() -> Command {
Command::new("book").about("Open The HEMTT book")
}
#[derive(clap::Parser)]
/// Open The HEMTT book
pub struct Command {}

/// Execute the book command
///
/// # Errors
/// Will not return an error
pub fn execute(_: &ArgMatches) -> Result<Report, Error> {
pub fn execute(_: &Command) -> Result<Report, Error> {
if let Err(e) = webbrowser::open("https://hemtt.dev/") {
eprintln!("Failed to open the HEMTT book: {e}");
}
Expand Down
69 changes: 27 additions & 42 deletions bin/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use clap::{ArgAction, ArgMatches, Command};

use crate::{
context::{self, Context},
error::Error,
Expand All @@ -10,51 +8,38 @@ use crate::{

use super::global_modules;

#[must_use]
pub fn cli() -> Command {
add_just(add_args(
Command::new("build")
.about("Build the project for final testing")
.long_about(
"Build your project in release mode for testing, without signing for full release.",
),
))
}
#[derive(clap::Parser)]
#[command(
long_about = "Build your project in release mode for testing, without signing for full release."
)]
/// Build the project for final testing
pub struct Command {
#[clap(flatten)]
build: Args,

#[must_use]
pub fn add_args(cmd: Command) -> Command {
cmd.arg(
clap::Arg::new("no-bin")
.long("no-bin")
.help("Do not binarize the project")
.action(ArgAction::SetTrue),
)
.arg(
clap::Arg::new("no-rap")
.long("no-rap")
.help("Do not rapify (cpp, rvmat)")
.action(ArgAction::SetTrue),
)
#[clap(flatten)]
just: super::JustArgs,
}

#[must_use]
pub fn add_just(cmd: Command) -> Command {
cmd.arg(
clap::Arg::new("just")
.long("just")
.help("Only build the given addon")
.action(ArgAction::Append),
)
#[derive(clap::Args)]
pub struct Args {
#[arg(long, action = clap::ArgAction::SetTrue)]
/// Do not binarize the project
no_bin: bool,
#[arg(long, action = clap::ArgAction::SetTrue)]
/// Do not rapify (cpp, rvmat)
no_rap: bool,
}

/// Execute the build command, build a new executor
///
/// # Errors
/// [`Error`] depending on the modules
pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
let just = matches
.get_many::<String>("just")
.unwrap_or_default()
pub fn execute(cmd: &Command) -> Result<Report, Error> {
let just = cmd
.just
.just
.iter()
.map(|s| s.to_lowercase())
.collect::<Vec<_>>();
let mut ctx = Context::new(
Expand All @@ -70,7 +55,7 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
if !just.is_empty() {
ctx = ctx.filter(|a, _| just.contains(&a.name().to_lowercase()));
}
let mut executor = executor(ctx, matches);
let mut executor = executor(ctx, &cmd.build);

if !just.is_empty() {
warn!("Use of `--just` is not recommended, only use it if you know what you're doing");
Expand All @@ -82,16 +67,16 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
}

#[must_use]
pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor {
pub fn executor(ctx: Context, args: &Args) -> Executor {
let mut executor = Executor::new(ctx);
global_modules(&mut executor);

executor.collapse(Collapse::No);

if matches.get_one::<bool>("no-rap") != Some(&true) {
if !args.no_rap {
executor.add_module(Box::<Rapifier>::default());
}
if matches.get_one::<bool>("no-bin") != Some(&true) {
if !args.no_bin {
executor.add_module(Box::<Binarize>::default());
}
executor.add_module(Box::<Files>::default());
Expand Down
11 changes: 4 additions & 7 deletions bin/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use clap::Command;

use crate::{
commands::global_modules,
context::Context,
Expand All @@ -9,16 +7,15 @@ use crate::{
report::Report,
};

#[must_use]
pub fn cli() -> Command {
Command::new("check").about("Check the project for errors")
}
#[derive(clap::Parser)]
/// Check the project for errors
pub struct Command {}

/// Execute the dev command
///
/// # Errors
/// [`Error`] depending on the modules
pub fn execute() -> Result<Report, Error> {
pub fn execute(_: &Command) -> Result<Report, Error> {
let ctx = Context::new(
Some("check"),
crate::context::PreservePrevious::Remove,
Expand Down
Loading

0 comments on commit 052ce69

Please sign in to comment.