mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
fix: Don't pollute root with str types
This commit is contained in:
parent
c6b8a7bafc
commit
276c75cc08
20 changed files with 56 additions and 53 deletions
|
@ -170,7 +170,7 @@ pub fn generate_to<G, S, T>(
|
|||
) -> Result<PathBuf, Error>
|
||||
where
|
||||
G: Generator,
|
||||
S: Into<clap::Str>,
|
||||
S: Into<clap::builder::Str>,
|
||||
T: Into<OsString>,
|
||||
{
|
||||
cmd.set_bin_name(bin_name);
|
||||
|
@ -223,7 +223,7 @@ where
|
|||
pub fn generate<G, S>(gen: G, cmd: &mut clap::Command, bin_name: S, buf: &mut dyn Write)
|
||||
where
|
||||
G: Generator,
|
||||
S: Into<clap::Str>,
|
||||
S: Into<clap::builder::Str>,
|
||||
{
|
||||
cmd.set_bin_name(bin_name);
|
||||
_generate::<G, S>(gen, cmd, buf)
|
||||
|
@ -232,7 +232,7 @@ where
|
|||
fn _generate<G, S>(gen: G, cmd: &mut clap::Command, buf: &mut dyn Write)
|
||||
where
|
||||
G: Generator,
|
||||
S: Into<clap::Str>,
|
||||
S: Into<clap::builder::Str>,
|
||||
{
|
||||
cmd.build();
|
||||
|
||||
|
|
|
@ -228,14 +228,14 @@ pub fn gen_augment(
|
|||
let next_display_order = attrs.next_display_order();
|
||||
if override_required {
|
||||
Some(quote_spanned! { kind.span()=>
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::Str::from(s.to_owned()));
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::builder::Str::from(s.to_owned()));
|
||||
let #app_var = #app_var #next_help_heading #next_display_order;
|
||||
let #app_var = <#ty as clap::Args>::augment_args_for_update(#app_var);
|
||||
let #app_var = #app_var.next_help_heading(clap::builder::Resettable::from(#old_heading_var));
|
||||
})
|
||||
} else {
|
||||
Some(quote_spanned! { kind.span()=>
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::Str::from(s.to_owned()));
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::builder::Str::from(s.to_owned()));
|
||||
let #app_var = #app_var #next_help_heading #next_display_order;
|
||||
let #app_var = <#ty as clap::Args>::augment_args(#app_var);
|
||||
let #app_var = #app_var.next_help_heading(clap::builder::Resettable::from(#old_heading_var));
|
||||
|
|
|
@ -193,14 +193,14 @@ fn gen_augment(
|
|||
let next_display_order = attrs.next_display_order();
|
||||
let subcommand = if override_required {
|
||||
quote! {
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::Str::from(s.to_owned()));
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::builder::Str::from(s.to_owned()));
|
||||
let #app_var = #app_var #next_help_heading #next_display_order;
|
||||
let #app_var = <#ty as clap::Subcommand>::augment_subcommands_for_update(#app_var);
|
||||
let #app_var = #app_var.next_help_heading(clap::builder::Resettable::from(#old_heading_var));
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::Str::from(s.to_owned()));
|
||||
let #old_heading_var = #app_var.get_next_help_heading().map(|s| clap::builder::Str::from(s.to_owned()));
|
||||
let #app_var = #app_var #next_help_heading #next_display_order;
|
||||
let #app_var = <#ty as clap::Subcommand>::augment_subcommands(#app_var);
|
||||
let #app_var = #app_var.next_help_heading(clap::builder::Resettable::from(#old_heading_var));
|
||||
|
|
|
@ -14,12 +14,12 @@ use std::{
|
|||
use super::{ArgFlags, ArgSettings};
|
||||
use crate::builder::ArgPredicate;
|
||||
use crate::builder::IntoResettable;
|
||||
use crate::builder::OsStr;
|
||||
use crate::builder::PossibleValue;
|
||||
use crate::builder::Str;
|
||||
use crate::builder::ValueRange;
|
||||
use crate::ArgAction;
|
||||
use crate::Id;
|
||||
use crate::OsStr;
|
||||
use crate::Str;
|
||||
use crate::ValueHint;
|
||||
use crate::INTERNAL_ERROR_MSG;
|
||||
|
||||
|
@ -3721,14 +3721,14 @@ impl Arg {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use clap::OsStr;
|
||||
/// # use std::ffi::OsStr;
|
||||
/// # use clap::Arg;
|
||||
/// let arg = Arg::new("foo").env("ENVIRONMENT");
|
||||
/// assert_eq!(arg.get_env(), Some(&OsStr::from("ENVIRONMENT")));
|
||||
/// assert_eq!(arg.get_env(), Some(OsStr::new("ENVIRONMENT")));
|
||||
/// ```
|
||||
#[cfg(feature = "env")]
|
||||
pub fn get_env(&self) -> Option<&OsStr> {
|
||||
self.env.as_ref().map(|x| &x.0)
|
||||
pub fn get_env(&self) -> Option<&std::ffi::OsStr> {
|
||||
self.env.as_ref().map(|x| x.0.as_os_str())
|
||||
}
|
||||
|
||||
/// Get the default values specified for this argument, if any
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::OsStr;
|
||||
use crate::builder::OsStr;
|
||||
|
||||
/// Operations to perform on argument values
|
||||
///
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::builder::arg_settings::ArgSettings;
|
|||
use crate::builder::ArgAction;
|
||||
use crate::builder::IntoResettable;
|
||||
use crate::builder::PossibleValue;
|
||||
use crate::builder::Str;
|
||||
use crate::builder::{Arg, ArgGroup, ArgPredicate};
|
||||
use crate::error::ErrorKind;
|
||||
use crate::error::Result as ClapResult;
|
||||
|
@ -22,7 +23,6 @@ use crate::parser::{ArgMatcher, ArgMatches, Parser};
|
|||
use crate::util::ChildGraph;
|
||||
use crate::util::FlatMap;
|
||||
use crate::util::{color::ColorChoice, Id};
|
||||
use crate::Str;
|
||||
use crate::{Error, INTERNAL_ERROR_MSG};
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
|
|
|
@ -2,12 +2,12 @@ use std::cmp::Ordering;
|
|||
|
||||
use clap_lex::RawOsStr;
|
||||
|
||||
use crate::builder::OsStr;
|
||||
use crate::builder::ValueRange;
|
||||
use crate::mkeymap::KeyType;
|
||||
use crate::util::FlatSet;
|
||||
use crate::util::Id;
|
||||
use crate::ArgAction;
|
||||
use crate::OsStr;
|
||||
use crate::INTERNAL_ERROR_MSG;
|
||||
use crate::{Arg, Command, ValueHint};
|
||||
|
||||
|
|
|
@ -7,9 +7,11 @@ mod arg_group;
|
|||
mod arg_predicate;
|
||||
mod arg_settings;
|
||||
mod command;
|
||||
mod os_str;
|
||||
mod possible_value;
|
||||
mod range;
|
||||
mod resettable;
|
||||
mod str;
|
||||
mod value_hint;
|
||||
mod value_parser;
|
||||
|
||||
|
@ -19,11 +21,13 @@ mod debug_asserts;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub use self::str::Str;
|
||||
pub use action::ArgAction;
|
||||
pub use arg::Arg;
|
||||
pub use arg_group::ArgGroup;
|
||||
pub use arg_predicate::ArgPredicate;
|
||||
pub use command::Command;
|
||||
pub use os_str::OsStr;
|
||||
pub use possible_value::PossibleValue;
|
||||
pub use range::ValueRange;
|
||||
pub use resettable::IntoResettable;
|
||||
|
@ -48,6 +52,8 @@ pub use value_parser::ValueParser;
|
|||
pub use value_parser::ValueParserFactory;
|
||||
pub use value_parser::_AnonymousValueParser;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use self::str::Inner as StrInner;
|
||||
pub(crate) use action::CountType;
|
||||
pub(crate) use arg::render_arg_val;
|
||||
pub(crate) use arg_settings::{ArgFlags, ArgSettings};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use crate::builder::Str;
|
||||
|
||||
/// A UTF-8-encoded fixed string
|
||||
#[derive(Default, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||
pub struct OsStr {
|
||||
|
@ -41,35 +43,35 @@ impl From<&'_ OsStr> for OsStr {
|
|||
}
|
||||
|
||||
#[cfg(feature = "perf")]
|
||||
impl From<crate::Str> for OsStr {
|
||||
fn from(id: crate::Str) -> Self {
|
||||
impl From<Str> for OsStr {
|
||||
fn from(id: Str) -> Self {
|
||||
match id.into_inner() {
|
||||
crate::util::StrInner::Static(s) => Self::from_static_ref(std::ffi::OsStr::new(s)),
|
||||
crate::util::StrInner::Owned(s) => Self::from_ref(std::ffi::OsStr::new(s.as_ref())),
|
||||
crate::builder::StrInner::Static(s) => Self::from_static_ref(std::ffi::OsStr::new(s)),
|
||||
crate::builder::StrInner::Owned(s) => Self::from_ref(std::ffi::OsStr::new(s.as_ref())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "perf"))]
|
||||
impl From<crate::Str> for OsStr {
|
||||
fn from(id: crate::Str) -> Self {
|
||||
impl From<Str> for OsStr {
|
||||
fn from(id: Str) -> Self {
|
||||
Self::from_ref(std::ffi::OsStr::new(id.as_str()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "perf")]
|
||||
impl From<&'_ crate::Str> for OsStr {
|
||||
fn from(id: &'_ crate::Str) -> Self {
|
||||
impl From<&'_ Str> for OsStr {
|
||||
fn from(id: &'_ Str) -> Self {
|
||||
match id.clone().into_inner() {
|
||||
crate::util::StrInner::Static(s) => Self::from_static_ref(std::ffi::OsStr::new(s)),
|
||||
crate::util::StrInner::Owned(s) => Self::from_ref(std::ffi::OsStr::new(s.as_ref())),
|
||||
crate::builder::StrInner::Static(s) => Self::from_static_ref(std::ffi::OsStr::new(s)),
|
||||
crate::builder::StrInner::Owned(s) => Self::from_ref(std::ffi::OsStr::new(s.as_ref())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "perf"))]
|
||||
impl From<&'_ crate::Str> for OsStr {
|
||||
fn from(id: &'_ crate::Str) -> Self {
|
||||
impl From<&'_ Str> for OsStr {
|
||||
fn from(id: &'_ Str) -> Self {
|
||||
Self::from_ref(std::ffi::OsStr::new(id.as_str()))
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use std::{borrow::Cow, iter};
|
||||
|
||||
use crate::builder::Str;
|
||||
use crate::util::eq_ignore_case;
|
||||
use crate::Str;
|
||||
|
||||
/// A possible value of an argument.
|
||||
///
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// Unlike `impl Into<Option<T>>` or `Option<impl Into<T>>`, this isn't ambiguous for the `None`
|
||||
// case.
|
||||
|
||||
use crate::builder::OsStr;
|
||||
use crate::builder::Str;
|
||||
|
||||
/// Clearable builder value
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum Resettable<T> {
|
||||
|
@ -40,8 +43,8 @@ pub trait IntoResettable<T> {
|
|||
fn into_resettable(self) -> Resettable<T>;
|
||||
}
|
||||
|
||||
impl IntoResettable<crate::OsStr> for Option<&'static str> {
|
||||
fn into_resettable(self) -> Resettable<crate::OsStr> {
|
||||
impl IntoResettable<OsStr> for Option<&'static str> {
|
||||
fn into_resettable(self) -> Resettable<OsStr> {
|
||||
match self {
|
||||
Some(s) => Resettable::Value(s.into()),
|
||||
None => Resettable::Reset,
|
||||
|
@ -49,8 +52,8 @@ impl IntoResettable<crate::OsStr> for Option<&'static str> {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoResettable<crate::Str> for Option<&'static str> {
|
||||
fn into_resettable(self) -> Resettable<crate::Str> {
|
||||
impl IntoResettable<Str> for Option<&'static str> {
|
||||
fn into_resettable(self) -> Resettable<Str> {
|
||||
match self {
|
||||
Some(s) => Resettable::Value(s.into()),
|
||||
None => Resettable::Reset,
|
||||
|
@ -64,14 +67,14 @@ impl<T> IntoResettable<T> for Resettable<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<I: Into<crate::OsStr>> IntoResettable<crate::OsStr> for I {
|
||||
fn into_resettable(self) -> Resettable<crate::OsStr> {
|
||||
impl<I: Into<OsStr>> IntoResettable<OsStr> for I {
|
||||
fn into_resettable(self) -> Resettable<OsStr> {
|
||||
Resettable::Value(self.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Into<crate::Str>> IntoResettable<crate::Str> for I {
|
||||
fn into_resettable(self) -> Resettable<crate::Str> {
|
||||
impl<I: Into<Str>> IntoResettable<Str> for I {
|
||||
fn into_resettable(self) -> Resettable<Str> {
|
||||
Resettable::Value(self.into())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,8 +109,6 @@ pub use crate::util::color::ColorChoice;
|
|||
#[allow(unused_imports)]
|
||||
pub(crate) use crate::util::color::ColorChoice;
|
||||
pub use crate::util::Id;
|
||||
pub use crate::util::OsStr;
|
||||
pub use crate::util::Str;
|
||||
|
||||
pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum};
|
||||
|
||||
|
|
|
@ -48,9 +48,9 @@ macro_rules! crate_authors {
|
|||
($sep:expr) => {{
|
||||
let authors = env!("CARGO_PKG_AUTHORS");
|
||||
if authors.contains(':') {
|
||||
$crate::Str::from(authors.replace(':', $sep))
|
||||
$crate::builder::Str::from(authors.replace(':', $sep))
|
||||
} else {
|
||||
$crate::Str::from(authors)
|
||||
$crate::builder::Str::from(authors)
|
||||
}
|
||||
}};
|
||||
() => {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::iter::Iterator;
|
||||
use std::ops::Index;
|
||||
|
||||
use crate::builder::OsStr;
|
||||
use crate::Arg;
|
||||
use crate::OsStr;
|
||||
use crate::INTERNAL_ERROR_MSG;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
|
|
|
@ -7,10 +7,10 @@ use std::usize;
|
|||
|
||||
// Internal
|
||||
use crate::builder::PossibleValue;
|
||||
use crate::builder::Str;
|
||||
use crate::builder::{render_arg_val, Arg, Command};
|
||||
use crate::output::{fmt::Colorizer, Usage};
|
||||
use crate::util::FlatSet;
|
||||
use crate::util::Str;
|
||||
use crate::ArgAction;
|
||||
|
||||
// Third party
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::iter::{Cloned, Flatten, Map};
|
|||
use std::slice::Iter;
|
||||
|
||||
// Internal
|
||||
use crate::builder::Str;
|
||||
use crate::parser::AnyValue;
|
||||
use crate::parser::AnyValueId;
|
||||
use crate::parser::MatchedArg;
|
||||
|
@ -13,7 +14,6 @@ use crate::parser::MatchesError;
|
|||
use crate::parser::ValueSource;
|
||||
use crate::util::FlatMap;
|
||||
use crate::util::Id;
|
||||
use crate::Str;
|
||||
use crate::INTERNAL_ERROR_MSG;
|
||||
|
||||
/// Container for parse results.
|
||||
|
|
|
@ -9,6 +9,7 @@ use clap_lex::RawOsStr;
|
|||
use clap_lex::RawOsString;
|
||||
|
||||
// Internal
|
||||
use crate::builder::Str;
|
||||
use crate::builder::{Arg, Command};
|
||||
use crate::error::Error as ClapError;
|
||||
use crate::error::Result as ClapResult;
|
||||
|
@ -21,7 +22,6 @@ use crate::parser::{ArgMatcher, SubCommand};
|
|||
use crate::parser::{Validator, ValueSource};
|
||||
use crate::util::Id;
|
||||
use crate::ArgAction;
|
||||
use crate::Str;
|
||||
use crate::{INTERNAL_ERROR_MSG, INVALID_UTF8};
|
||||
|
||||
pub(crate) struct Parser<'cmd> {
|
||||
|
@ -1425,7 +1425,7 @@ impl<'cmd> Parser<'cmd> {
|
|||
let arg_values: Vec<_> = arg
|
||||
.default_vals
|
||||
.iter()
|
||||
.map(crate::OsStr::to_os_string)
|
||||
.map(crate::builder::OsStr::to_os_string)
|
||||
.collect();
|
||||
let trailing_idx = None;
|
||||
let _ = self.react(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::Str;
|
||||
use crate::builder::Str;
|
||||
|
||||
/// [`Arg`][crate::Arg] or [`ArgGroup`][crate::ArgGroup] identifier
|
||||
///
|
||||
|
|
|
@ -4,20 +4,14 @@ mod flat_map;
|
|||
mod flat_set;
|
||||
mod graph;
|
||||
mod id;
|
||||
mod os_str;
|
||||
mod str;
|
||||
mod str_to_bool;
|
||||
|
||||
pub use self::id::Id;
|
||||
pub use self::os_str::OsStr;
|
||||
pub use self::str::Str;
|
||||
|
||||
pub(crate) use self::flat_map::Entry;
|
||||
pub(crate) use self::flat_map::FlatMap;
|
||||
pub(crate) use self::flat_set::FlatSet;
|
||||
pub(crate) use self::graph::ChildGraph;
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use self::str::Inner as StrInner;
|
||||
pub(crate) use self::str_to_bool::str_to_bool;
|
||||
pub(crate) use self::str_to_bool::FALSE_LITERALS;
|
||||
pub(crate) use self::str_to_bool::TRUE_LITERALS;
|
||||
|
|
Loading…
Reference in a new issue