Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the cargo cli style #411

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cargo = "0.82.0"
cargo-util = "0.2"
semver = "1.0.3"
log = "0.4"
clap = { version = "4.0.29", features = ["color", "derive", "cargo", "string"] }
clap = { version = "4.5.18", features = ["color", "derive", "cargo", "string", "wrap_help"] }
regex = "1.5.6"
cbindgen = { version="0.27.0", default-features=false }
toml = "0.8"
Expand Down
21 changes: 9 additions & 12 deletions src/bin/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ fn main() -> CliResult {
let cli_install = subcommand_install("install", "Install the crate C-API");
let cli_test = subcommand_test("test");

let mut app = clap::command!()
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(
Command::new("capi")
.allow_external_subcommands(true)
.about("Build or install the crate C-API")
.arg(flag("version", "Print version info and exit").short('V'))
.subcommand(cli_build)
.subcommand(cli_install)
.subcommand(cli_test),
);
let mut app = main_cli().subcommand(
Command::new("capi")
.allow_external_subcommands(true)
.about("Build or install the crate C-API")
.arg(flag("version", "Print version info and exit").short('V'))
.subcommand(cli_build)
.subcommand(cli_install)
.subcommand(cli_test),
);

let args = app.clone().get_matches();

Expand Down
8 changes: 2 additions & 6 deletions src/bin/cbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ use cargo::CliResult;
use cargo::GlobalContext;

use cargo_c::build::*;
use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_build;
use cargo_c::cli::{main_cli, run_cargo_fallback, subcommand_build};
use cargo_c::config::*;

fn main() -> CliResult {
let mut config = GlobalContext::default()?;

let subcommand = subcommand_build("cbuild", "Build the crate C-API");
let mut app = clap::command!()
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);
let mut app = main_cli().subcommand(subcommand);

let args = app.clone().get_matches();

Expand Down
8 changes: 2 additions & 6 deletions src/bin/cinstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ use cargo::CliResult;
use cargo::GlobalContext;

use cargo_c::build::cbuild;
use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_install;
use cargo_c::cli::{main_cli, run_cargo_fallback, subcommand_install};
use cargo_c::config::global_context_configure;
use cargo_c::install::cinstall;

fn main() -> CliResult {
let mut config = GlobalContext::default()?;

let subcommand = subcommand_install("cinstall", "Install the crate C-API");
let mut app = clap::command!()
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);
let mut app = main_cli().subcommand(subcommand);

let args = app.clone().get_matches();

Expand Down
8 changes: 2 additions & 6 deletions src/bin/ctest.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use cargo::util::command_prelude::*;

use cargo_c::build::*;
use cargo_c::cli::run_cargo_fallback;
use cargo_c::cli::subcommand_test;
use cargo_c::cli::{main_cli, run_cargo_fallback, subcommand_test};
use cargo_c::config::*;

fn main() -> CliResult {
let mut config = GlobalContext::default()?;

let subcommand = subcommand_test("ctest");

let mut app = clap::command!()
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.subcommand(subcommand);
let mut app = main_cli().subcommand(subcommand);

let args = app.clone().get_matches();

Expand Down
19 changes: 18 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;

use cargo::util::command_prelude::CommandExt;
use cargo::util::command_prelude::{flag, multi_opt, opt};
use cargo::util::{CliError, CliResult};
use cargo::util::{style, CliError, CliResult};

use cargo_util::{ProcessBuilder, ProcessError};

Expand Down Expand Up @@ -57,6 +57,23 @@ struct Common {
meson: bool,
}

pub fn main_cli() -> Command {
let styles = {
clap::builder::styling::Styles::styled()
.header(style::HEADER)
.usage(style::USAGE)
.literal(style::LITERAL)
.placeholder(style::PLACEHOLDER)
.error(style::ERROR)
.valid(style::VALID)
.invalid(style::INVALID)
};
clap::command!()
.dont_collapse_args_in_usage(true)
.allow_external_subcommands(true)
.styles(styles)
}

fn base_cli() -> Command {
let default_target = Target::new::<&str>(None, false);
let app = Common::command()
Expand Down
Loading