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

fix: Deprecate most AppSettings #3449

Merged
merged 4 commits into from Feb 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/03_complex.rs
@@ -1,4 +1,4 @@
use clap::{arg, App, AppSettings, Arg};
use clap::{arg, App, Arg};
use criterion::{criterion_group, criterion_main, Criterion};

static OPT3_VALS: [&str; 2] = ["fast", "slow"];
Expand Down Expand Up @@ -257,7 +257,7 @@ pub fn parse_args_negate_scs(c: &mut Criterion) {
c.bench_function("parse_args_negate_scs", |b| {
b.iter(|| {
create_app!()
.setting(AppSettings::ArgsNegateSubcommands)
.args_conflicts_with_subcommands(true)
.get_matches_from(vec![
"myprog",
"arg1",
Expand Down
20 changes: 10 additions & 10 deletions benches/06_rustup.rs
Expand Up @@ -43,7 +43,7 @@ fn build_cli() -> App<'static> {
App::new("install")
.about("Update Rust toolchains")
.after_help(TOOLCHAIN_INSTALL_HELP)
.setting(AppSettings::Hidden) // synonym for 'toolchain install'
.hide(true) // synonym for 'toolchain install'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
Expand Down Expand Up @@ -89,17 +89,17 @@ fn build_cli() -> App<'static> {
)
.subcommand(
App::new("update")
.setting(AppSettings::Hidden) // synonym for 'install'
.hide(true) // synonym for 'install'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
App::new("add")
.setting(AppSettings::Hidden) // synonym for 'install'
.hide(true) // synonym for 'install'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
App::new("remove")
.setting(AppSettings::Hidden) // synonym for 'uninstall'
.hide(true) // synonym for 'uninstall'
.arg(Arg::new("toolchain").required(true)),
),
)
Expand Down Expand Up @@ -127,13 +127,13 @@ fn build_cli() -> App<'static> {
)
.subcommand(
App::new("install")
.setting(AppSettings::Hidden) // synonym for 'add'
.hide(true) // synonym for 'add'
.arg(Arg::new("target").required(true))
.arg(Arg::new("toolchain").long("toolchain").takes_value(true)),
)
.subcommand(
App::new("uninstall")
.setting(AppSettings::Hidden) // synonym for 'remove'
.hide(true) // synonym for 'remove'
.arg(Arg::new("target").required(true))
.arg(Arg::new("toolchain").long("toolchain").takes_value(true)),
),
Expand Down Expand Up @@ -193,12 +193,12 @@ fn build_cli() -> App<'static> {
)
.subcommand(
App::new("add")
.setting(AppSettings::Hidden) // synonym for 'set'
.hide(true) // synonym for 'set'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
App::new("remove")
.setting(AppSettings::Hidden) // synonym for 'unset'
.hide(true) // synonym for 'unset'
.about("Remove the override toolchain for a directory")
.arg(Arg::new("path").long("path").takes_value(true))
.arg(
Expand All @@ -212,7 +212,7 @@ fn build_cli() -> App<'static> {
App::new("run")
.about("Run a command with an environment configured for a given toolchain")
.after_help(RUN_HELP)
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(Arg::new("toolchain").required(true))
.arg(
Arg::new("command")
Expand Down Expand Up @@ -264,7 +264,7 @@ fn build_cli() -> App<'static> {
.subcommand(
App::new("telemetry")
.about("rustup telemetry commands")
.setting(AppSettings::Hidden)
.hide(true)
.setting(AppSettings::DeriveDisplayOrder)
.subcommand(App::new("enable").about("Enable rustup telemetry"))
.subcommand(App::new("disable").about("Disable rustup telemetry"))
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/examples/value_hints.rs
Expand Up @@ -12,14 +12,14 @@
//! . ./value_hints.fish
//! ./target/debug/examples/value_hints --<TAB>
//! ```
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::{generate, Generator, Shell};
use std::io;

fn build_cli() -> App<'static> {
App::new("value_hints")
// AppSettings::TrailingVarArg is required to use ValueHint::CommandWithArguments
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(
Arg::new("generator")
.long("generate")
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/examples/value_hints_derive.rs
Expand Up @@ -12,7 +12,7 @@
//! . ./value_hints_derive.fish
//! ./target/debug/examples/value_hints_derive --<TAB>
//! ```
use clap::{App, AppSettings, IntoApp, Parser, ValueHint};
use clap::{App, IntoApp, Parser, ValueHint};
use clap_complete::{generate, Generator, Shell};
use std::ffi::OsString;
use std::io;
Expand All @@ -21,8 +21,8 @@ use std::path::PathBuf;
#[derive(Parser, Debug, PartialEq)]
#[clap(
name = "value_hints_derive",
// AppSettings::TrailingVarArg is required to use ValueHint::CommandWithArguments
setting = AppSettings::TrailingVarArg,
// App::trailing_var_ar is required to use ValueHint::CommandWithArguments
trailing_var_arg = true,
)]
struct Opt {
/// If provided, outputs the completion file for given shell
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/completions/bash.rs
Expand Up @@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/completions/elvish.rs
Expand Up @@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/completions/fish.rs
Expand Up @@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/completions/mod.rs
@@ -1,4 +1,4 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::{generate, shells::*, Generator};
use std::fmt;

Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/completions/powershell.rs
Expand Up @@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/completions/zsh.rs
Expand Up @@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Test test's completions")
.arg(
Arg::new("file")
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/tests/value_hints.rs
@@ -1,13 +1,13 @@
mod completions;

use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};

use clap_complete::shells::*;
use completions::common;

pub fn build_app_with_value_hints() -> App<'static> {
App::new("my_app")
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(
Arg::new("choice")
.long("choice")
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_fig/tests/completions/fig.rs
Expand Up @@ -8,7 +8,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_fig/tests/completions/mod.rs
@@ -1,4 +1,4 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::{generate, Generator};
use std::fmt;

Expand Down
6 changes: 3 additions & 3 deletions clap_complete_fig/tests/value_hints.rs
@@ -1,13 +1,13 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete_fig::Fig;
use completions::common;

mod completions;

pub fn build_app_with_value_hints() -> App<'static> {
App::new("my_app")
.setting(AppSettings::DisableVersionFlag)
.setting(AppSettings::TrailingVarArg)
.disable_version_flag(true)
.trailing_var_arg(true)
.arg(
Arg::new("choice")
.long("choice")
Expand Down
4 changes: 2 additions & 2 deletions clap_derive/src/derives/subcommand.rs
Expand Up @@ -165,11 +165,11 @@ fn gen_augment(
Some(subty) => {
if is_simple_ty(subty, "OsString") {
quote_spanned! { kind.span()=>
let #app_var = #app_var.setting(clap::AppSettings::AllowExternalSubcommands).setting(clap::AppSettings::AllowInvalidUtf8ForExternalSubcommands);
let #app_var = #app_var.allow_external_subcommands(true).allow_invalid_utf8_for_external_subcommands(true);
}
} else {
quote_spanned! { kind.span()=>
let #app_var = #app_var.setting(clap::AppSettings::AllowExternalSubcommands);
let #app_var = #app_var.allow_external_subcommands(true);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions clap_mangen/src/lib.rs
Expand Up @@ -264,6 +264,5 @@ fn app_has_arguments(app: &clap::App) -> bool {

// Does the application have any subcommands?
fn app_has_subcommands(app: &clap::App) -> bool {
app.get_subcommands()
.any(|i| !i.is_set(clap::AppSettings::Hidden))
app.get_subcommands().any(|i| !i.is_hide_set())
}
10 changes: 2 additions & 8 deletions clap_mangen/src/render.rs
Expand Up @@ -144,10 +144,7 @@ pub(crate) fn options(roff: &mut Roff, app: &clap::App) {
}

pub(crate) fn subcommands(roff: &mut Roff, app: &clap::App, section: &str) {
for sub in app
.get_subcommands()
.filter(|s| !s.is_set(AppSettings::Hidden))
{
for sub in app.get_subcommands().filter(|s| !s.is_hide_set()) {
roff.control("TP", []);

let name = format!("{}-{}({})", app.get_name(), sub.get_name(), section);
Expand Down Expand Up @@ -179,10 +176,7 @@ pub(crate) fn after_help(roff: &mut Roff, app: &clap::App) {
}

fn subcommand_markers(cmd: &clap::App) -> (&'static str, &'static str) {
markers(
cmd.is_set(AppSettings::SubcommandRequired)
|| cmd.is_set(AppSettings::SubcommandRequiredElseHelp),
)
markers(cmd.is_subcommand_required_set() || cmd.is_set(AppSettings::SubcommandRequiredElseHelp))
}

fn option_markers(opt: &clap::Arg) -> (&'static str, &'static str) {
Expand Down
2 changes: 1 addition & 1 deletion examples/cargo-example.rs
Expand Up @@ -3,7 +3,7 @@
fn main() {
let app = clap::App::new("cargo")
.bin_name("cargo")
.setting(clap::AppSettings::SubcommandRequired)
.subcommand_required(true)
.subcommand(
clap::app_from_crate!().name("example").arg(
clap::arg!(--"manifest-path" <PATH>)
Expand Down
8 changes: 4 additions & 4 deletions examples/git-derive.rs
Expand Up @@ -3,7 +3,7 @@
use std::ffi::OsString;
use std::path::PathBuf;

use clap::{AppSettings, Parser, Subcommand};
use clap::{Parser, Subcommand};

/// A fictional versioning CLI
#[derive(Parser)]
Expand All @@ -17,19 +17,19 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Clones repos
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[clap(arg_required_else_help = true)]
Clone {
/// The remote to clone
remote: String,
},
/// pushes things
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[clap(arg_required_else_help = true)]
Push {
/// The remote to target
remote: String,
},
/// adds things
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[clap(arg_required_else_help = true)]
Add {
/// Stuff to add
#[clap(required = true, parse(from_os_str))]
Expand Down
10 changes: 5 additions & 5 deletions examples/git.rs
Expand Up @@ -8,24 +8,24 @@ fn main() {
let matches = App::new("git")
.about("A fictional versioning CLI")
.setting(AppSettings::SubcommandRequiredElseHelp)
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.subcommand(
App::new("clone")
.about("Clones repos")
.arg(arg!(<REMOTE> "The remote to clone"))
.setting(AppSettings::ArgRequiredElseHelp),
.arg_required_else_help(true),
)
.subcommand(
App::new("push")
.about("pushes things")
.arg(arg!(<REMOTE> "The remote to target"))
.setting(AppSettings::ArgRequiredElseHelp),
.arg_required_else_help(true),
)
.subcommand(
App::new("add")
.about("adds things")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.arg(arg!(<PATH> ... "Stuff to add").allow_invalid_utf8(true)),
)
.get_matches();
Expand Down
6 changes: 3 additions & 3 deletions examples/multicall-busybox.rs
Expand Up @@ -2,7 +2,7 @@

use std::process::exit;

use clap::{App, AppSettings, Arg};
use clap::{App, Arg};

fn applet_commands() -> [App<'static>; 2] {
[
Expand All @@ -13,10 +13,10 @@ fn applet_commands() -> [App<'static>; 2] {

fn main() {
let app = App::new(env!("CARGO_CRATE_NAME"))
.setting(AppSettings::Multicall)
.multicall(true)
.subcommand(
App::new("busybox")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.subcommand_value_name("APPLET")
.subcommand_help_heading("APPLETS")
.arg(
Expand Down
6 changes: 3 additions & 3 deletions examples/multicall-hostname.rs
@@ -1,16 +1,16 @@
// Note: this requires the `unstable-multicall` feature

use clap::{App, AppSettings};
use clap::App;

fn main() {
let app = App::new(env!("CARGO_CRATE_NAME"))
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.subcommand_value_name("APPLET")
.subcommand_help_heading("APPLETS")
.subcommand(App::new("hostname").about("show hostname part of FQDN"))
.subcommand(App::new("dnsdomainname").about("show domain name part of FQDN"));

let app = app.setting(AppSettings::Multicall);
let app = app.multicall(true);

match app.get_matches().subcommand_name() {
Some("hostname") => println!("www"),
Expand Down