Merge pull request #44 from epage/examples

docs: Prefer `global_setting`
This commit is contained in:
Ed Page 2021-11-29 16:40:20 -06:00 committed by GitHub
commit ea73ec521b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 18 deletions

View file

@ -135,7 +135,7 @@ The first example shows the simplest way to use `clap`, by defining a struct. If
// //
// This example demonstrates clap's full 'custom derive' style of creating arguments which is the // This example demonstrates clap's full 'custom derive' style of creating arguments which is the
// simplest method of use, but sacrifices some flexibility. // simplest method of use, but sacrifices some flexibility.
use clap::{AppSettings, Parser}; use clap::Parser;
/// This doc string acts as a help message when the user runs '--help' /// This doc string acts as a help message when the user runs '--help'
/// as do all doc strings on fields /// as do all doc strings on fields

View file

@ -4,7 +4,7 @@ use clap::{AppSettings, Parser};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
// https://docs.rs/clap/2/clap/enum.AppSettings.html#variant.InferSubcommands // https://docs.rs/clap/2/clap/enum.AppSettings.html#variant.InferSubcommands
#[clap(setting = AppSettings::InferSubcommands)] #[clap(global_setting = AppSettings::InferSubcommands)]
enum Opt { enum Opt {
// https://docs.rs/clap/2/clap/struct.App.html#method.alias // https://docs.rs/clap/2/clap/struct.App.html#method.alias
#[clap(alias = "foobar")] #[clap(alias = "foobar")]

View file

@ -935,14 +935,14 @@ impl<'help> App<'help> {
/// # use clap::{App, AppSettings}; /// # use clap::{App, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::SubcommandRequired) /// .setting(AppSettings::SubcommandRequired)
/// .setting(AppSettings::WaitOnError) /// .setting(AppSettings::AllowLeadingHyphen)
/// # ; /// # ;
/// ``` /// ```
/// or /// or
/// ```no_run /// ```no_run
/// # use clap::{App, AppSettings}; /// # use clap::{App, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::SubcommandRequired | AppSettings::WaitOnError) /// .setting(AppSettings::SubcommandRequired | AppSettings::AllowLeadingHyphen)
/// # ; /// # ;
/// ``` /// ```
#[inline] #[inline]
@ -964,14 +964,14 @@ impl<'help> App<'help> {
/// # use clap::{App, AppSettings}; /// # use clap::{App, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .unset_setting(AppSettings::SubcommandRequired) /// .unset_setting(AppSettings::SubcommandRequired)
/// .unset_setting(AppSettings::WaitOnError) /// .setting(AppSettings::AllowLeadingHyphen)
/// # ; /// # ;
/// ``` /// ```
/// or /// or
/// ```no_run /// ```no_run
/// # use clap::{App, AppSettings}; /// # use clap::{App, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .unset_setting(AppSettings::SubcommandRequired | AppSettings::WaitOnError) /// .unset_setting(AppSettings::SubcommandRequired | AppSettings::AllowLeadingHyphen)
/// # ; /// # ;
/// ``` /// ```
#[inline] #[inline]
@ -994,7 +994,7 @@ impl<'help> App<'help> {
/// ```no_run /// ```no_run
/// # use clap::{App, AppSettings}; /// # use clap::{App, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .global_setting(AppSettings::SubcommandRequired) /// .global_setting(AppSettings::AllowNegativeNumbers)
/// # ; /// # ;
/// ``` /// ```
#[inline] #[inline]

View file

@ -268,7 +268,7 @@ pub enum AppSettings {
/// ```rust /// ```rust
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// let res = App::new("myprog") /// let res = App::new("myprog")
/// .setting(AppSettings::AllowNegativeNumbers) /// .global_setting(AppSettings::AllowNegativeNumbers)
/// .arg(Arg::new("num")) /// .arg(Arg::new("num"))
/// .try_get_matches_from(vec![ /// .try_get_matches_from(vec![
/// "myprog", "-20" /// "myprog", "-20"
@ -547,7 +547,7 @@ pub enum AppSettings {
/// ```no_run /// ```no_run
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::DontCollapseArgsInUsage) /// .global_setting(AppSettings::DontCollapseArgsInUsage)
/// .get_matches(); /// .get_matches();
/// ``` /// ```
DontCollapseArgsInUsage, DontCollapseArgsInUsage,
@ -645,7 +645,7 @@ pub enum AppSettings {
/// ```no_run /// ```no_run
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::DeriveDisplayOrder) /// .global_setting(AppSettings::DeriveDisplayOrder)
/// .get_matches(); /// .get_matches();
/// ``` /// ```
/// ///
@ -750,7 +750,7 @@ pub enum AppSettings {
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .version("v1.1") /// .version("v1.1")
/// .setting(AppSettings::PropagateVersion) /// .global_setting(AppSettings::PropagateVersion)
/// .subcommand(App::new("test")) /// .subcommand(App::new("test"))
/// .get_matches(); /// .get_matches();
/// // running `$ myprog test --version` will display /// // running `$ myprog test --version` will display
@ -803,7 +803,7 @@ pub enum AppSettings {
/// ```rust /// ```rust
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::HelpExpected) /// .global_setting(AppSettings::HelpExpected)
/// .arg( /// .arg(
/// Arg::new("foo").help("It does foo stuff") /// Arg::new("foo").help("It does foo stuff")
/// // As required via AppSettings::HelpExpected, a help message was supplied /// // As required via AppSettings::HelpExpected, a help message was supplied
@ -816,7 +816,7 @@ pub enum AppSettings {
/// ```rust,no_run /// ```rust,no_run
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myapp") /// App::new("myapp")
/// .setting(AppSettings::HelpExpected) /// .global_setting(AppSettings::HelpExpected)
/// .arg( /// .arg(
/// Arg::new("foo") /// Arg::new("foo")
/// // Someone forgot to put .about("...") here /// // Someone forgot to put .about("...") here
@ -835,7 +835,7 @@ pub enum AppSettings {
/// ```rust /// ```rust
/// # use clap::{App, arg, AppSettings}; /// # use clap::{App, arg, AppSettings};
/// let app = App::new("app") /// let app = App::new("app")
/// .setting(AppSettings::IgnoreErrors) /// .global_setting(AppSettings::IgnoreErrors)
/// .arg(arg!(-c --config <FILE> "Sets a custom config file").required(false)) /// .arg(arg!(-c --config <FILE> "Sets a custom config file").required(false))
/// .arg(arg!(-x --stuff <FILE> "Sets a custom stuff file").required(false)) /// .arg(arg!(-x --stuff <FILE> "Sets a custom stuff file").required(false))
/// .arg(arg!(f: -f "Flag")); /// .arg(arg!(f: -f "Flag"));
@ -869,7 +869,7 @@ pub enum AppSettings {
/// ```no_run /// ```no_run
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// let m = App::new("prog") /// let m = App::new("prog")
/// .setting(AppSettings::InferSubcommands) /// .global_setting(AppSettings::InferSubcommands)
/// .subcommand(App::new("test")) /// .subcommand(App::new("test"))
/// .get_matches_from(vec![ /// .get_matches_from(vec![
/// "prog", "te" /// "prog", "te"
@ -921,7 +921,7 @@ pub enum AppSettings {
/// ```no_run /// ```no_run
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::NextLineHelp) /// .global_setting(AppSettings::NextLineHelp)
/// .get_matches(); /// .get_matches();
/// ``` /// ```
NextLineHelp, NextLineHelp,
@ -1004,7 +1004,7 @@ pub enum AppSettings {
/// ```rust /// ```rust
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::UseLongFormatForHelpSubcommand) /// .global_setting(AppSettings::UseLongFormatForHelpSubcommand)
/// .subcommand(App::new("test") /// .subcommand(App::new("test")
/// .arg(Arg::new("foo") /// .arg(Arg::new("foo")
/// .help("short form about message") /// .help("short form about message")
@ -1075,7 +1075,7 @@ pub enum AppSettings {
/// ```rust /// ```rust
/// # use clap::{App, Arg, AppSettings}; /// # use clap::{App, Arg, AppSettings};
/// App::new("myprog") /// App::new("myprog")
/// .setting(AppSettings::WaitOnError); /// .global_setting(AppSettings::WaitOnError);
/// ``` /// ```
WaitOnError, WaitOnError,