mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
fix: Rename IntoApp to CommandFactory
This is part of the `App` rename. Previously, I was concerned about not being able to deprecate For backwards compatibility, we still expose the `IntoApp` name.
This commit is contained in:
parent
c3fec1fa75
commit
ddac492302
15 changed files with 56 additions and 46 deletions
|
@ -12,7 +12,7 @@
|
|||
//! . ./value_hints_derive.fish
|
||||
//! ./target/debug/examples/value_hints_derive --<TAB>
|
||||
//! ```
|
||||
use clap::{Command, IntoApp, Parser, ValueHint};
|
||||
use clap::{Command, CommandFactory, Parser, ValueHint};
|
||||
use clap_complete::{generate, Generator, Shell};
|
||||
use std::ffi::OsString;
|
||||
use std::io;
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn gen_for_struct(
|
|||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
#[allow(deprecated)]
|
||||
impl #impl_generics clap::IntoApp for #struct_name #ty_generics #where_clause {
|
||||
impl #impl_generics clap::CommandFactory for #struct_name #ty_generics #where_clause {
|
||||
fn into_app<'b>() -> clap::Command<'b> {
|
||||
let #app_var = clap::Command::new(#name);
|
||||
<Self as clap::Args>::augment_args(#app_var)
|
||||
|
@ -102,7 +102,7 @@ pub fn gen_for_enum(enum_name: &Ident, generics: &Generics, attrs: &[Attribute])
|
|||
clippy::suspicious_else_formatting,
|
||||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl #impl_generics clap::IntoApp for #enum_name #ty_generics #where_clause {
|
||||
impl #impl_generics clap::CommandFactory for #enum_name #ty_generics #where_clause {
|
||||
fn into_app<'b>() -> clap::Command<'b> {
|
||||
#[allow(deprecated)]
|
||||
let #app_var = clap::Command::new(#name)
|
||||
|
|
|
@ -19,7 +19,7 @@ pub fn parser_enum(name: &Ident) {
|
|||
pub fn into_app(name: &Ident) {
|
||||
append_dummy(quote! {
|
||||
#[allow(deprecated)]
|
||||
impl clap::IntoApp for #name {
|
||||
impl clap::CommandFactory for #name {
|
||||
fn into_app<'b>() -> clap::Command<'b> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::{ErrorKind, IntoApp, Parser};
|
||||
use clap::{CommandFactory, ErrorKind, Parser};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
|
|
|
@ -16,6 +16,6 @@ fn main() {
|
|||
|
||||
#[test]
|
||||
fn verify_app() {
|
||||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
Cli::command().debug_assert()
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ use crate::build::debug_asserts::assert_app;
|
|||
/// arguments (or lack thereof).
|
||||
///
|
||||
/// When deriving a [`Parser`][crate::Parser], you can use
|
||||
/// [`IntoApp::into_app`][crate::IntoApp::into_app] to access the
|
||||
/// [`CommandFactory::into_app`][crate::CommandFactory::into_app] to access the
|
||||
/// `Command`.
|
||||
///
|
||||
/// # Examples
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::ffi::OsString;
|
|||
/// into concrete instance of the user struct.
|
||||
///
|
||||
/// This trait is primarily a convenience on top of [`FromArgMatches`] +
|
||||
/// [`IntoApp`] which uses those two underlying traits to build the two
|
||||
/// [`CommandFactory`] which uses those two underlying traits to build the two
|
||||
/// fundamental functions `parse` which uses the `std::env::args_os` iterator,
|
||||
/// and `parse_from` which allows the consumer to supply the iterator (along
|
||||
/// with fallible options for each).
|
||||
|
@ -76,10 +76,10 @@ use std::ffi::OsString;
|
|||
/// }
|
||||
/// ```
|
||||
///
|
||||
pub trait Parser: FromArgMatches + IntoApp + Sized {
|
||||
pub trait Parser: FromArgMatches + CommandFactory + Sized {
|
||||
/// Parse from `std::env::args_os()`, exit on error
|
||||
fn parse() -> Self {
|
||||
let matches = <Self as IntoApp>::command().get_matches();
|
||||
let matches = <Self as CommandFactory>::command().get_matches();
|
||||
let res =
|
||||
<Self as FromArgMatches>::from_arg_matches(&matches).map_err(format_error::<Self>);
|
||||
match res {
|
||||
|
@ -94,7 +94,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
|
||||
/// Parse from `std::env::args_os()`, return Err on error.
|
||||
fn try_parse() -> Result<Self, Error> {
|
||||
let matches = <Self as IntoApp>::command().try_get_matches()?;
|
||||
let matches = <Self as CommandFactory>::command().try_get_matches()?;
|
||||
<Self as FromArgMatches>::from_arg_matches(&matches).map_err(format_error::<Self>)
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
I: IntoIterator<Item = T>,
|
||||
T: Into<OsString> + Clone,
|
||||
{
|
||||
let matches = <Self as IntoApp>::command().get_matches_from(itr);
|
||||
let matches = <Self as CommandFactory>::command().get_matches_from(itr);
|
||||
let res =
|
||||
<Self as FromArgMatches>::from_arg_matches(&matches).map_err(format_error::<Self>);
|
||||
match res {
|
||||
|
@ -123,7 +123,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
I: IntoIterator<Item = T>,
|
||||
T: Into<OsString> + Clone,
|
||||
{
|
||||
let matches = <Self as IntoApp>::command().try_get_matches_from(itr)?;
|
||||
let matches = <Self as CommandFactory>::command().try_get_matches_from(itr)?;
|
||||
<Self as FromArgMatches>::from_arg_matches(&matches).map_err(format_error::<Self>)
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
I: IntoIterator<Item = T>,
|
||||
T: Into<OsString> + Clone,
|
||||
{
|
||||
let matches = <Self as IntoApp>::command().get_matches_from(itr);
|
||||
let matches = <Self as CommandFactory>::command_for_update().get_matches_from(itr);
|
||||
let res = <Self as FromArgMatches>::update_from_arg_matches(self, &matches)
|
||||
.map_err(format_error::<Self>);
|
||||
if let Err(e) = res {
|
||||
|
@ -149,7 +149,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
I: IntoIterator<Item = T>,
|
||||
T: Into<OsString> + Clone,
|
||||
{
|
||||
let matches = <Self as IntoApp>::command().try_get_matches_from(itr)?;
|
||||
let matches = <Self as CommandFactory>::command_for_update().try_get_matches_from(itr)?;
|
||||
<Self as FromArgMatches>::update_from_arg_matches(self, &matches)
|
||||
.map_err(format_error::<Self>)
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
)]
|
||||
#[doc(hidden)]
|
||||
fn clap<'help>() -> Command<'help> {
|
||||
<Self as IntoApp>::command()
|
||||
<Self as CommandFactory>::command()
|
||||
}
|
||||
|
||||
/// Deprecated, `StructOpt::from_clap` replaced with [`FromArgMatches::from_arg_matches`] (derive as part of
|
||||
|
@ -229,7 +229,7 @@ pub trait Parser: FromArgMatches + IntoApp + Sized {
|
|||
/// Create an [`Command`] relevant for a user-defined container.
|
||||
///
|
||||
/// Derived as part of [`Parser`].
|
||||
pub trait IntoApp: Sized {
|
||||
pub trait CommandFactory: Sized {
|
||||
/// Build an [`Command`] that can instantiate `Self`.
|
||||
///
|
||||
/// See [`FromArgMatches::from_arg_matches`] for instantiating `Self`.
|
||||
|
@ -237,8 +237,8 @@ pub trait IntoApp: Sized {
|
|||
#[allow(deprecated)]
|
||||
Self::into_app()
|
||||
}
|
||||
/// Deprecated, replaced with `IntoApp::command`
|
||||
#[deprecated(since = "3.1.0", note = "Replaced with `IntoApp::command")]
|
||||
/// Deprecated, replaced with `CommandFactory::command`
|
||||
#[deprecated(since = "3.1.0", note = "Replaced with `CommandFactory::command")]
|
||||
fn into_app<'help>() -> Command<'help>;
|
||||
/// Build an [`Command`] that can update `self`.
|
||||
///
|
||||
|
@ -247,8 +247,11 @@ pub trait IntoApp: Sized {
|
|||
#[allow(deprecated)]
|
||||
Self::into_app_for_update()
|
||||
}
|
||||
/// Deprecated, replaced with `IntoApp::command_for_update`
|
||||
#[deprecated(since = "3.1.0", note = "Replaced with `IntoApp::command_for_update")]
|
||||
/// Deprecated, replaced with `CommandFactory::command_for_update`
|
||||
#[deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `CommandFactory::command_for_update"
|
||||
)]
|
||||
fn into_app_for_update<'help>() -> Command<'help>;
|
||||
}
|
||||
|
||||
|
@ -327,13 +330,13 @@ pub trait FromArgMatches: Sized {
|
|||
pub trait Args: FromArgMatches + Sized {
|
||||
/// Append to [`Command`] so it can instantiate `Self`.
|
||||
///
|
||||
/// See also [`IntoApp`].
|
||||
/// See also [`CommandFactory`].
|
||||
fn augment_args(cmd: Command<'_>) -> Command<'_>;
|
||||
/// Append to [`Command`] so it can update `self`.
|
||||
///
|
||||
/// This is used to implement `#[clap(flatten)]`
|
||||
///
|
||||
/// See also [`IntoApp`].
|
||||
/// See also [`CommandFactory`].
|
||||
fn augment_args_for_update(cmd: Command<'_>) -> Command<'_>;
|
||||
}
|
||||
|
||||
|
@ -371,13 +374,13 @@ pub trait Args: FromArgMatches + Sized {
|
|||
pub trait Subcommand: FromArgMatches + Sized {
|
||||
/// Append to [`Command`] so it can instantiate `Self`.
|
||||
///
|
||||
/// See also [`IntoApp`].
|
||||
/// See also [`CommandFactory`].
|
||||
fn augment_subcommands(cmd: Command<'_>) -> Command<'_>;
|
||||
/// Append to [`Command`] so it can update `self`.
|
||||
///
|
||||
/// This is used to implement `#[clap(flatten)]`
|
||||
///
|
||||
/// See also [`IntoApp`].
|
||||
/// See also [`CommandFactory`].
|
||||
fn augment_subcommands_for_update(cmd: Command<'_>) -> Command<'_>;
|
||||
/// Test whether `Self` can parse a specific subcommand
|
||||
fn has_subcommand(name: &str) -> bool;
|
||||
|
@ -464,12 +467,12 @@ impl<T: Parser> Parser for Box<T> {
|
|||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<T: IntoApp> IntoApp for Box<T> {
|
||||
impl<T: CommandFactory> CommandFactory for Box<T> {
|
||||
fn into_app<'help>() -> Command<'help> {
|
||||
<T as IntoApp>::into_app()
|
||||
<T as CommandFactory>::into_app()
|
||||
}
|
||||
fn into_app_for_update<'help>() -> Command<'help> {
|
||||
<T as IntoApp>::into_app_for_update()
|
||||
<T as CommandFactory>::into_app_for_update()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,7 +506,7 @@ impl<T: Subcommand> Subcommand for Box<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn format_error<I: IntoApp>(err: crate::Error) -> crate::Error {
|
||||
fn format_error<I: CommandFactory>(err: crate::Error) -> crate::Error {
|
||||
let mut cmd = I::command();
|
||||
err.format(&mut cmd)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ pub use crate::parse::{ArgMatches, Indices, OsValues, ValueSource, Values};
|
|||
#[cfg(feature = "color")]
|
||||
pub use crate::util::color::ColorChoice;
|
||||
|
||||
pub use crate::derive::{ArgEnum, Args, FromArgMatches, IntoApp, Parser, Subcommand};
|
||||
pub use crate::derive::{ArgEnum, Args, CommandFactory, FromArgMatches, Parser, Subcommand};
|
||||
|
||||
pub use crate::error::{ErrorKind, Result};
|
||||
|
||||
|
@ -55,6 +55,10 @@ pub use yaml_rust::YamlLoader;
|
|||
#[doc(hidden)]
|
||||
pub use clap_derive::{self, *};
|
||||
|
||||
/// Deprecated, replaced with [`CommandFactory`]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `CommandFactory`")]
|
||||
#[doc(hidden)]
|
||||
pub use CommandFactory as IntoApp;
|
||||
/// Deprecated, replaced with [`Parser`]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `Parser`")]
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
use clap::Parser;
|
||||
#[test]
|
||||
fn app_name_in_short_help_from_struct() {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
|
||||
// MIT/Apache 2.0 license.
|
||||
|
||||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
use clap::Parser;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -144,7 +144,8 @@ fn update_every_custom_parser() {
|
|||
d: "D",
|
||||
};
|
||||
|
||||
opt.update_from(&["test", "-a=?", "-b=?", "-d=?"]);
|
||||
opt.try_update_from(&["test", "-a=?", "-b=?", "-d=?"])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
NoOpOpt {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::{IntoApp, Parser};
|
||||
use clap::{CommandFactory, Parser};
|
||||
|
||||
use crate::utils;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use crate::utils;
|
||||
|
||||
use clap::{ArgEnum, IntoApp, Parser};
|
||||
use clap::{ArgEnum, CommandFactory, Parser};
|
||||
|
||||
#[test]
|
||||
fn doc_comments() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::{AppSettings, Args, IntoApp, Parser, Subcommand};
|
||||
use clap::{AppSettings, Args, CommandFactory, Parser, Subcommand};
|
||||
|
||||
#[test]
|
||||
fn arg_help_heading_applied() {
|
||||
|
@ -277,7 +277,7 @@ OPTIONS:
|
|||
option_b: Option<String>,
|
||||
}
|
||||
|
||||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
let mut cmd = Args::command();
|
||||
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
|
@ -334,7 +334,7 @@ OPTIONS:
|
|||
option_b: Option<String>,
|
||||
}
|
||||
|
||||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
let mut cmd = Args::command();
|
||||
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
|
@ -390,7 +390,7 @@ OPTIONS:
|
|||
option_b: Option<String>,
|
||||
}
|
||||
|
||||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
let mut cmd = Args::command();
|
||||
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
// Accept and endure. Do not touch.
|
||||
#![allow(unused)]
|
||||
|
||||
use clap::IntoApp;
|
||||
use clap::CommandFactory;
|
||||
|
||||
pub fn get_help<T: IntoApp>() -> String {
|
||||
pub fn get_help<T: CommandFactory>() -> String {
|
||||
let mut output = Vec::new();
|
||||
<T as IntoApp>::command().write_help(&mut output).unwrap();
|
||||
<T as CommandFactory>::command()
|
||||
.write_help(&mut output)
|
||||
.unwrap();
|
||||
let output = String::from_utf8(output).unwrap();
|
||||
|
||||
eprintln!("\n%%% HELP %%%:=====\n{}\n=====\n", output);
|
||||
|
@ -18,9 +20,9 @@ pub fn get_help<T: IntoApp>() -> String {
|
|||
output
|
||||
}
|
||||
|
||||
pub fn get_long_help<T: IntoApp>() -> String {
|
||||
pub fn get_long_help<T: CommandFactory>() -> String {
|
||||
let mut output = Vec::new();
|
||||
<T as IntoApp>::command()
|
||||
<T as CommandFactory>::command()
|
||||
.write_long_help(&mut output)
|
||||
.unwrap();
|
||||
let output = String::from_utf8(output).unwrap();
|
||||
|
@ -31,9 +33,9 @@ pub fn get_long_help<T: IntoApp>() -> String {
|
|||
output
|
||||
}
|
||||
|
||||
pub fn get_subcommand_long_help<T: IntoApp>(subcmd: &str) -> String {
|
||||
pub fn get_subcommand_long_help<T: CommandFactory>(subcmd: &str) -> String {
|
||||
let mut output = Vec::new();
|
||||
<T as IntoApp>::command()
|
||||
<T as CommandFactory>::command()
|
||||
.get_subcommands_mut()
|
||||
.find(|s| s.get_name() == subcmd)
|
||||
.unwrap()
|
||||
|
|
Loading…
Reference in a new issue