mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
Remove _some_ of pubs
This commit is contained in:
parent
bc738e12c2
commit
4fc4a00b8f
15 changed files with 140 additions and 461 deletions
|
@ -1,5 +1,6 @@
|
||||||
mod settings;
|
mod settings;
|
||||||
pub use self::settings::{AppFlags, AppSettings};
|
|
||||||
|
pub use self::settings::AppSettings;
|
||||||
|
|
||||||
// Std
|
// Std
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -15,7 +16,7 @@ use std::process;
|
||||||
use yaml_rust::Yaml;
|
use yaml_rust::Yaml;
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
use crate::build::{Arg, ArgGroup, ArgSettings};
|
use crate::build::{app::settings::AppFlags, Arg, ArgGroup, ArgSettings};
|
||||||
use crate::mkeymap::MKeyMap;
|
use crate::mkeymap::MKeyMap;
|
||||||
use crate::output::fmt::ColorWhen;
|
use crate::output::fmt::ColorWhen;
|
||||||
use crate::output::{Help, Usage};
|
use crate::output::{Help, Usage};
|
||||||
|
@ -26,9 +27,10 @@ use crate::INTERNAL_ERROR_MSG;
|
||||||
|
|
||||||
type Id = u64;
|
type Id = u64;
|
||||||
|
|
||||||
#[doc(hidden)]
|
// FIXME (@CreepySkeleton): some of this variants are never constructed
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Propagation {
|
#[allow(unused)]
|
||||||
|
pub(crate) enum Propagation {
|
||||||
To(Id),
|
To(Id),
|
||||||
Full,
|
Full,
|
||||||
NextLevel,
|
NextLevel,
|
||||||
|
@ -65,56 +67,37 @@ pub enum Propagation {
|
||||||
/// [`App::get_matches`]: ./struct.App.html#method.get_matches
|
/// [`App::get_matches`]: ./struct.App.html#method.get_matches
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(Default, Debug, Clone)]
|
||||||
pub struct App<'b> {
|
pub struct App<'b> {
|
||||||
#[doc(hidden)]
|
pub(crate) id: Id,
|
||||||
pub id: Id,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub bin_name: Option<String>,
|
pub bin_name: Option<String>,
|
||||||
#[doc(hidden)]
|
pub(crate) author: Option<&'b str>,
|
||||||
pub author: Option<&'b str>,
|
pub(crate) version: Option<&'b str>,
|
||||||
#[doc(hidden)]
|
pub(crate) long_version: Option<&'b str>,
|
||||||
pub version: Option<&'b str>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub long_version: Option<&'b str>,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub about: Option<&'b str>,
|
pub about: Option<&'b str>,
|
||||||
#[doc(hidden)]
|
pub(crate) long_about: Option<&'b str>,
|
||||||
pub long_about: Option<&'b str>,
|
pub(crate) more_help: Option<&'b str>,
|
||||||
#[doc(hidden)]
|
pub(crate) pre_help: Option<&'b str>,
|
||||||
pub more_help: Option<&'b str>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub pre_help: Option<&'b str>,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub aliases: Option<Vec<(&'b str, bool)>>, // (name, visible)
|
pub aliases: Option<Vec<(&'b str, bool)>>, // (name, visible)
|
||||||
#[doc(hidden)]
|
pub(crate) usage_str: Option<&'b str>,
|
||||||
pub usage_str: Option<&'b str>,
|
pub(crate) usage: Option<String>,
|
||||||
#[doc(hidden)]
|
pub(crate) help_str: Option<&'b str>,
|
||||||
pub usage: Option<String>,
|
pub(crate) disp_ord: usize,
|
||||||
#[doc(hidden)]
|
pub(crate) term_w: Option<usize>,
|
||||||
pub help_str: Option<&'b str>,
|
pub(crate) max_w: Option<usize>,
|
||||||
#[doc(hidden)]
|
pub(crate) template: Option<&'b str>,
|
||||||
pub disp_ord: usize,
|
pub(crate) settings: AppFlags,
|
||||||
#[doc(hidden)]
|
pub(crate) g_settings: AppFlags,
|
||||||
pub term_w: Option<usize>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub max_w: Option<usize>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub template: Option<&'b str>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub settings: AppFlags,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub g_settings: AppFlags,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub args: MKeyMap<'b>,
|
pub args: MKeyMap<'b>,
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub subcommands: Vec<App<'b>>,
|
pub subcommands: Vec<App<'b>>,
|
||||||
#[doc(hidden)]
|
pub(crate) replacers: HashMap<&'b str, &'b [&'b str]>,
|
||||||
pub replacers: HashMap<&'b str, &'b [&'b str]>,
|
pub(crate) groups: Vec<ArgGroup<'b>>,
|
||||||
#[doc(hidden)]
|
pub(crate) help_headings: Vec<Option<&'b str>>,
|
||||||
pub groups: Vec<ArgGroup<'b>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub help_headings: Vec<Option<&'b str>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b> App<'b> {
|
impl<'b> App<'b> {
|
||||||
|
@ -1532,7 +1515,7 @@ impl<'b> App<'b> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _propagate(&mut self, prop: Propagation) {
|
pub(crate) fn _propagate(&mut self, prop: Propagation) {
|
||||||
macro_rules! propagate_subcmd {
|
macro_rules! propagate_subcmd {
|
||||||
($_self:expr, $sc:expr) => {{
|
($_self:expr, $sc:expr) => {{
|
||||||
// We have to create a new scope in order to tell rustc the borrow of `sc` is
|
// We have to create a new scope in order to tell rustc the borrow of `sc` is
|
||||||
|
@ -1794,7 +1777,7 @@ impl<'b> App<'b> {
|
||||||
|
|
||||||
// Should we color the output? None=determined by output location, true=yes, false=no
|
// Should we color the output? None=determined by output location, true=yes, false=no
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn color(&self) -> ColorWhen {
|
pub(crate) fn color(&self) -> ColorWhen {
|
||||||
debugln!("App::color;");
|
debugln!("App::color;");
|
||||||
debug!("App::color: Color setting...");
|
debug!("App::color: Color setting...");
|
||||||
if self.is_set(AppSettings::ColorNever) {
|
if self.is_set(AppSettings::ColorNever) {
|
||||||
|
@ -1821,55 +1804,31 @@ impl<'b> App<'b> {
|
||||||
self.settings.is_set(s) || self.g_settings.is_set(s)
|
self.settings.is_set(s) || self.g_settings.is_set(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, s: AppSettings) {
|
|
||||||
self.settings.set(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_global(&mut self, s: AppSettings) {
|
|
||||||
self.g_settings.set(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unset_global(&mut self, s: AppSettings) {
|
|
||||||
self.g_settings.unset(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unset(&mut self, s: AppSettings) {
|
|
||||||
self.settings.unset(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_subcommands(&self) -> bool {
|
pub fn has_subcommands(&self) -> bool {
|
||||||
!self.subcommands.is_empty()
|
!self.subcommands.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_args(&self) -> bool {
|
pub(crate) fn set(&mut self, s: AppSettings) {
|
||||||
|
self.settings.set(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn unset(&mut self, s: AppSettings) {
|
||||||
|
self.settings.unset(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn has_args(&self) -> bool {
|
||||||
!self.args.is_empty()
|
!self.args.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_opts(&self) -> bool {
|
pub(crate) fn has_opts(&self) -> bool {
|
||||||
opts!(self).count() > 0
|
opts!(self).count() > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_flags(&self) -> bool {
|
pub(crate) fn has_flags(&self) -> bool {
|
||||||
flags!(self).count() > 0
|
flags!(self).count() > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_positionals(&self) -> bool {
|
pub(crate) fn has_visible_subcommands(&self) -> bool {
|
||||||
positionals!(self).count() > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_visible_opts(&self) -> bool {
|
|
||||||
opts!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_visible_flags(&self) -> bool {
|
|
||||||
flags!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_visible_positionals(&self) -> bool {
|
|
||||||
positionals!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_visible_subcommands(&self) -> bool {
|
|
||||||
subcommands!(self)
|
subcommands!(self)
|
||||||
.filter(|sc| sc.name != "help")
|
.filter(|sc| sc.name != "help")
|
||||||
.any(|sc| !sc.is_set(AppSettings::Hidden))
|
.any(|sc| !sc.is_set(AppSettings::Hidden))
|
||||||
|
|
|
@ -52,7 +52,7 @@ bitflags! {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
pub struct AppFlags(Flags);
|
pub(crate) struct AppFlags(Flags);
|
||||||
|
|
||||||
impl BitOr for AppFlags {
|
impl BitOr for AppFlags {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
@ -67,15 +67,6 @@ impl Default for AppFlags {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppFlags {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
AppFlags::default()
|
|
||||||
}
|
|
||||||
pub fn zeroed() -> Self {
|
|
||||||
AppFlags(Flags::empty())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_settings! { AppSettings, AppFlags,
|
impl_settings! { AppSettings, AppFlags,
|
||||||
ArgRequiredElseHelp("argrequiredelsehelp")
|
ArgRequiredElseHelp("argrequiredelsehelp")
|
||||||
=> Flags::A_REQUIRED_ELSE_HELP,
|
=> Flags::A_REQUIRED_ELSE_HELP,
|
||||||
|
@ -659,7 +650,7 @@ pub enum AppSettings {
|
||||||
HidePossibleValuesInHelp,
|
HidePossibleValuesInHelp,
|
||||||
|
|
||||||
/// Tells `clap` to panic if help strings are omitted
|
/// Tells `clap` to panic if help strings are omitted
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
mod settings;
|
mod settings;
|
||||||
pub use self::settings::{ArgFlags, ArgSettings};
|
|
||||||
|
pub use self::settings::ArgSettings;
|
||||||
|
|
||||||
// Std
|
// Std
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -18,7 +19,7 @@ use crate::util::VecMap;
|
||||||
use yaml_rust;
|
use yaml_rust;
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
use crate::build::UsageParser;
|
use crate::build::{arg::settings::ArgFlags, usage_parser::UsageParser};
|
||||||
use crate::util::Key;
|
use crate::util::Key;
|
||||||
#[cfg(any(target_os = "windows", target_arch = "wasm32"))]
|
#[cfg(any(target_os = "windows", target_arch = "wasm32"))]
|
||||||
use crate::util::OsStrExt3;
|
use crate::util::OsStrExt3;
|
||||||
|
@ -54,70 +55,46 @@ type Id = u64;
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct Arg<'help> {
|
pub struct Arg<'help> {
|
||||||
#[doc(hidden)]
|
pub(crate) id: Id,
|
||||||
pub id: Id,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub name: &'help str,
|
pub name: &'help str,
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub help: Option<&'help str>,
|
pub help: Option<&'help str>,
|
||||||
#[doc(hidden)]
|
pub(crate) long_help: Option<&'help str>,
|
||||||
pub long_help: Option<&'help str>,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub blacklist: Option<Vec<Id>>,
|
pub blacklist: Option<Vec<Id>>,
|
||||||
#[doc(hidden)]
|
pub(crate) settings: ArgFlags,
|
||||||
pub settings: ArgFlags,
|
pub(crate) r_unless: Option<Vec<Id>>,
|
||||||
#[doc(hidden)]
|
pub(crate) overrides: Option<Vec<Id>>,
|
||||||
pub r_unless: Option<Vec<Id>>,
|
pub(crate) groups: Option<Vec<Id>>,
|
||||||
#[doc(hidden)]
|
pub(crate) requires: Option<Vec<(Option<&'help str>, Id)>>,
|
||||||
pub overrides: Option<Vec<Id>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub groups: Option<Vec<Id>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub requires: Option<Vec<(Option<&'help str>, Id)>>,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub short: Option<char>,
|
pub short: Option<char>,
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub long: Option<&'help str>,
|
pub long: Option<&'help str>,
|
||||||
#[doc(hidden)]
|
pub(crate) aliases: Option<Vec<(&'help str, bool)>>, // (name, visible)
|
||||||
pub aliases: Option<Vec<(&'help str, bool)>>, // (name, visible)
|
pub(crate) disp_ord: usize,
|
||||||
#[doc(hidden)]
|
pub(crate) unified_ord: usize,
|
||||||
pub disp_ord: usize,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub unified_ord: usize,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub possible_vals: Option<Vec<&'help str>>,
|
pub possible_vals: Option<Vec<&'help str>>,
|
||||||
#[doc(hidden)]
|
pub(crate) val_names: Option<VecMap<&'help str>>,
|
||||||
pub val_names: Option<VecMap<&'help str>>,
|
pub(crate) num_vals: Option<u64>,
|
||||||
#[doc(hidden)]
|
pub(crate) max_vals: Option<u64>,
|
||||||
pub num_vals: Option<u64>,
|
pub(crate) min_vals: Option<u64>,
|
||||||
#[doc(hidden)]
|
pub(crate) validator: Option<Validator>,
|
||||||
pub max_vals: Option<u64>,
|
pub(crate) validator_os: Option<ValidatorOs>,
|
||||||
#[doc(hidden)]
|
pub(crate) val_delim: Option<char>,
|
||||||
pub min_vals: Option<u64>,
|
pub(crate) default_vals: Option<Vec<&'help OsStr>>,
|
||||||
#[doc(hidden)]
|
pub(crate) default_vals_ifs: Option<VecMap<(Id, Option<&'help OsStr>, &'help OsStr)>>,
|
||||||
pub validator: Option<Validator>,
|
pub(crate) env: Option<(&'help OsStr, Option<OsString>)>,
|
||||||
#[doc(hidden)]
|
pub(crate) terminator: Option<&'help str>,
|
||||||
pub validator_os: Option<ValidatorOs>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub val_delim: Option<char>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub default_vals: Option<Vec<&'help OsStr>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub default_vals_ifs: Option<VecMap<(Id, Option<&'help OsStr>, &'help OsStr)>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub env: Option<(&'help OsStr, Option<OsString>)>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub terminator: Option<&'help str>,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub index: Option<u64>,
|
pub index: Option<u64>,
|
||||||
#[doc(hidden)]
|
pub(crate) r_ifs: Option<Vec<(Id, &'help str)>>,
|
||||||
pub r_ifs: Option<Vec<(Id, &'help str)>>,
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub help_heading: Option<&'help str>,
|
pub help_heading: Option<&'help str>,
|
||||||
#[doc(hidden)]
|
pub(crate) global: bool,
|
||||||
pub global: bool,
|
pub(crate) exclusive: bool,
|
||||||
#[doc(hidden)]
|
|
||||||
pub exclusive: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'help> Arg<'help> {
|
impl<'help> Arg<'help> {
|
||||||
|
@ -817,7 +794,7 @@ impl<'help> Arg<'help> {
|
||||||
/// assert!(res.is_err());
|
/// assert!(res.is_err());
|
||||||
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
|
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Arg::conflicts_with_all(names)`]: ./struct.Arg.html#method.conflicts_with_all
|
/// [`Arg::conflicts_with_all(names)`]: ./struct.Arg.html#method.conflicts_with_all
|
||||||
/// [`Arg::exclusive(true)`]: ./struct.Arg.html#method.exclusive
|
/// [`Arg::exclusive(true)`]: ./struct.Arg.html#method.exclusive
|
||||||
|
|
||||||
|
@ -4066,6 +4043,7 @@ impl<'help> Arg<'help> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: (@CreepySkeleton)
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn _build(&mut self) {
|
pub fn _build(&mut self) {
|
||||||
if (self.is_set(ArgSettings::UseValueDelimiter)
|
if (self.is_set(ArgSettings::UseValueDelimiter)
|
||||||
|
@ -4092,30 +4070,25 @@ impl<'help> Arg<'help> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO @p6 @naming @internal: rename to set_mut
|
// @TODO @p6 @naming @internal: rename to set_mut
|
||||||
#[doc(hidden)]
|
pub(crate) fn setb(&mut self, s: ArgSettings) {
|
||||||
pub fn setb(&mut self, s: ArgSettings) {
|
|
||||||
self.settings.set(s);
|
self.settings.set(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO @p6 @naming @internal: rename to unset_mut
|
// @TODO @p6 @naming @internal: rename to unset_mut
|
||||||
#[doc(hidden)]
|
pub(crate) fn unsetb(&mut self, s: ArgSettings) {
|
||||||
pub fn unsetb(&mut self, s: ArgSettings) {
|
|
||||||
self.settings.unset(s);
|
self.settings.unset(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
pub(crate) fn has_switch(&self) -> bool {
|
||||||
pub fn has_switch(&self) -> bool {
|
|
||||||
self.short.is_some() || self.long.is_some()
|
self.short.is_some() || self.long.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
pub(crate) fn longest_filter(&self) -> bool {
|
||||||
pub fn longest_filter(&self) -> bool {
|
|
||||||
self.is_set(ArgSettings::TakesValue) || self.long.is_some() || self.short.is_none()
|
self.is_set(ArgSettings::TakesValue) || self.long.is_some() || self.short.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for positionals when printing
|
// Used for positionals when printing
|
||||||
#[doc(hidden)]
|
pub(crate) fn multiple_str(&self) -> &str {
|
||||||
pub fn multiple_str(&self) -> &str {
|
|
||||||
let mult_vals = self
|
let mult_vals = self
|
||||||
.val_names
|
.val_names
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -4131,8 +4104,7 @@ impl<'help> Arg<'help> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for positionals when printing
|
// Used for positionals when printing
|
||||||
#[doc(hidden)]
|
pub(crate) fn name_no_brackets(&self) -> Cow<str> {
|
||||||
pub fn name_no_brackets(&self) -> Cow<str> {
|
|
||||||
debugln!("PosBuilder::name_no_brackets:{}", self.name);
|
debugln!("PosBuilder::name_no_brackets:{}", self.name);
|
||||||
let mut delim = String::new();
|
let mut delim = String::new();
|
||||||
delim.push(if self.is_set(ArgSettings::RequireDelimiter) {
|
delim.push(if self.is_set(ArgSettings::RequireDelimiter) {
|
||||||
|
|
|
@ -31,13 +31,7 @@ bitflags! {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct ArgFlags(Flags);
|
pub(crate) struct ArgFlags(Flags);
|
||||||
|
|
||||||
impl ArgFlags {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
ArgFlags::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @TODO @p6 @internal: Reorder alphabetically
|
// @TODO @p6 @internal: Reorder alphabetically
|
||||||
impl_settings! { ArgSettings, ArgFlags,
|
impl_settings! { ArgSettings, ArgFlags,
|
||||||
|
|
|
@ -82,25 +82,17 @@ type Id = u64;
|
||||||
/// [requirement]: ./struct.Arg.html#method.requires
|
/// [requirement]: ./struct.Arg.html#method.requires
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ArgGroup<'a> {
|
pub struct ArgGroup<'a> {
|
||||||
#[doc(hidden)]
|
pub(crate) id: Id,
|
||||||
pub id: Id,
|
pub(crate) name: &'a str,
|
||||||
#[doc(hidden)]
|
pub(crate) args: Vec<Id>,
|
||||||
pub name: &'a str,
|
pub(crate) required: bool,
|
||||||
#[doc(hidden)]
|
pub(crate) requires: Option<Vec<Id>>,
|
||||||
pub args: Vec<Id>,
|
pub(crate) conflicts: Option<Vec<Id>>,
|
||||||
#[doc(hidden)]
|
pub(crate) multiple: bool,
|
||||||
pub required: bool,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub requires: Option<Vec<Id>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub conflicts: Option<Vec<Id>>,
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub multiple: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ArgGroup<'a> {
|
impl<'a> ArgGroup<'a> {
|
||||||
#[doc(hidden)]
|
pub(crate) fn _with_id(id: Id) -> Self {
|
||||||
pub fn _with_id(id: Id) -> Self {
|
|
||||||
ArgGroup {
|
ArgGroup {
|
||||||
id,
|
id,
|
||||||
..ArgGroup::default()
|
..ArgGroup::default()
|
||||||
|
|
|
@ -7,7 +7,6 @@ pub mod arg;
|
||||||
mod arg_group;
|
mod arg_group;
|
||||||
mod usage_parser;
|
mod usage_parser;
|
||||||
|
|
||||||
pub use self::app::{App, AppFlags, AppSettings, Propagation};
|
pub use self::app::{App, AppSettings};
|
||||||
pub use self::arg::{Arg, ArgFlags, ArgSettings};
|
pub use self::arg::{Arg, ArgSettings};
|
||||||
pub use self::arg_group::ArgGroup;
|
pub use self::arg_group::ArgGroup;
|
||||||
pub use self::usage_parser::UsageParser;
|
|
||||||
|
|
|
@ -15,9 +15,8 @@ enum UsageToken {
|
||||||
Default,
|
Default,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UsageParser<'a> {
|
pub(crate) struct UsageParser<'a> {
|
||||||
usage: &'a str,
|
usage: &'a str,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
start: usize,
|
start: usize,
|
||||||
|
@ -37,12 +36,12 @@ impl<'a> UsageParser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_usage(usage: &'a str) -> Self {
|
pub(crate) fn from_usage(usage: &'a str) -> Self {
|
||||||
debugln!("UsageParser::from_usage;");
|
debugln!("UsageParser::from_usage;");
|
||||||
UsageParser::new(usage)
|
UsageParser::new(usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(mut self) -> Arg<'a> {
|
pub(crate) fn parse(mut self) -> Arg<'a> {
|
||||||
debugln!("UsageParser::parse;");
|
debugln!("UsageParser::parse;");
|
||||||
let mut arg = Arg::default();
|
let mut arg = Arg::default();
|
||||||
arg.disp_ord = 999;
|
arg.disp_ord = 999;
|
||||||
|
|
|
@ -445,11 +445,10 @@
|
||||||
)]
|
)]
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
compile_error!("`std` feature is currently required to build this crate");
|
compile_error!("`std` feature is currently required to build `clap`");
|
||||||
|
|
||||||
pub use crate::build::{App, AppSettings, Arg, ArgGroup, ArgSettings, Propagation};
|
pub use crate::build::{App, AppSettings, Arg, ArgGroup, ArgSettings};
|
||||||
pub use crate::derive::{Clap, FromArgMatches, IntoApp, Subcommand};
|
pub use crate::derive::{Clap, FromArgMatches, IntoApp, Subcommand};
|
||||||
pub use crate::output::fmt::Format;
|
|
||||||
pub use crate::parse::errors::{Error, ErrorKind, Result};
|
pub use crate::parse::errors::{Error, ErrorKind, Result};
|
||||||
pub use crate::parse::{ArgMatches, OsValues, SubCommand, Values};
|
pub use crate::parse::{ArgMatches, OsValues, SubCommand, Values};
|
||||||
|
|
||||||
|
@ -464,9 +463,6 @@ pub use clap_derive::{self, *};
|
||||||
#[cfg_attr(feature = "derive", doc(hidden))]
|
#[cfg_attr(feature = "derive", doc(hidden))]
|
||||||
pub use lazy_static;
|
pub use lazy_static;
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub use mkeymap::KeyType;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
|
|
|
@ -829,19 +829,19 @@ macro_rules! impl_settings {
|
||||||
$( $setting:ident($str:expr) => $flag:path ),+
|
$( $setting:ident($str:expr) => $flag:path ),+
|
||||||
) => {
|
) => {
|
||||||
impl $flags {
|
impl $flags {
|
||||||
pub fn set(&mut self, s: $settings) {
|
pub(crate) fn set(&mut self, s: $settings) {
|
||||||
match s {
|
match s {
|
||||||
$($settings::$setting => self.0.insert($flag)),*
|
$($settings::$setting => self.0.insert($flag)),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unset(&mut self, s: $settings) {
|
pub(crate) fn unset(&mut self, s: $settings) {
|
||||||
match s {
|
match s {
|
||||||
$($settings::$setting => self.0.remove($flag)),*
|
$($settings::$setting => self.0.remove($flag)),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_set(&self, s: $settings) -> bool {
|
pub(crate) fn is_set(&self, s: $settings) -> bool {
|
||||||
match s {
|
match s {
|
||||||
$($settings::$setting => self.0.contains($flag)),*
|
$($settings::$setting => self.0.contains($flag)),*
|
||||||
}
|
}
|
||||||
|
@ -927,7 +927,7 @@ macro_rules! flags {
|
||||||
$app.args
|
$app.args
|
||||||
.args
|
.args
|
||||||
.$how()
|
.$how()
|
||||||
.filter(|a| !a.settings.is_set($crate::ArgSettings::TakesValue) && a.index.is_none())
|
.filter(|a| !a.is_set($crate::ArgSettings::TakesValue) && a.index.is_none())
|
||||||
.filter(|a| !a.help_heading.is_some())
|
.filter(|a| !a.help_heading.is_some())
|
||||||
}};
|
}};
|
||||||
($app:expr) => {
|
($app:expr) => {
|
||||||
|
@ -942,7 +942,7 @@ macro_rules! opts {
|
||||||
$app.args
|
$app.args
|
||||||
.args
|
.args
|
||||||
.$how()
|
.$how()
|
||||||
.filter(|a| a.settings.is_set($crate::ArgSettings::TakesValue) && a.index.is_none())
|
.filter(|a| a.is_set($crate::ArgSettings::TakesValue) && a.index.is_none())
|
||||||
.filter(|a| !a.help_heading.is_some())
|
.filter(|a| !a.help_heading.is_some())
|
||||||
}};
|
}};
|
||||||
($app:expr) => {
|
($app:expr) => {
|
||||||
|
|
247
src/mkeymap.rs
247
src/mkeymap.rs
|
@ -4,21 +4,22 @@ use std::ffi::{OsStr, OsString};
|
||||||
type Id = u64;
|
type Id = u64;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
pub struct Key {
|
pub(crate) struct Key {
|
||||||
pub key: KeyType,
|
pub(crate) key: KeyType,
|
||||||
pub index: usize,
|
pub(crate) index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug, Clone)]
|
#[derive(Default, PartialEq, Debug, Clone)]
|
||||||
pub struct MKeyMap<'b> {
|
pub struct MKeyMap<'b> {
|
||||||
pub keys: Vec<Key>,
|
pub(crate) keys: Vec<Key>,
|
||||||
pub args: Vec<Arg<'b>>,
|
pub args: Vec<Arg<'b>>,
|
||||||
|
|
||||||
|
// FIXME (@CreepySkeleton): this seems useless
|
||||||
built: bool, // mutation isn't possible after being built
|
built: bool, // mutation isn't possible after being built
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||||
pub enum KeyType {
|
pub(crate) enum KeyType {
|
||||||
Short(char),
|
Short(char),
|
||||||
Long(OsString),
|
Long(OsString),
|
||||||
Position(u64),
|
Position(u64),
|
||||||
|
@ -52,36 +53,17 @@ impl PartialEq<char> for KeyType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b> MKeyMap<'b> {
|
impl<'b> MKeyMap<'b> {
|
||||||
pub fn new() -> Self {
|
|
||||||
MKeyMap::default()
|
|
||||||
}
|
|
||||||
//TODO ::from(x), ::with_capacity(n) etc
|
//TODO ::from(x), ::with_capacity(n) etc
|
||||||
//? set theory ops?
|
//? set theory ops?
|
||||||
|
|
||||||
#[deprecated(since = "3.0.0", note = "Use `contains` instead")]
|
pub(crate) fn contains<K>(&self, key: K) -> bool
|
||||||
pub fn contains_long(&self, l: &str) -> bool {
|
|
||||||
self.contains(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(since = "3.0.0", note = "Use `contains` instead")]
|
|
||||||
pub fn contains_short(&self, c: char) -> bool {
|
|
||||||
self.contains(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contains<K>(&self, key: K) -> bool
|
|
||||||
where
|
where
|
||||||
KeyType: PartialEq<K>,
|
KeyType: PartialEq<K>,
|
||||||
{
|
{
|
||||||
self.keys.iter().any(|x| x.key == key)
|
self.keys.iter().any(|x| x.key == key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, key: KeyType, value: Arg<'b>) -> usize {
|
pub(crate) fn push(&mut self, value: Arg<'b>) -> usize {
|
||||||
let index = self.push(value);
|
|
||||||
self.keys.push(Key { key, index });
|
|
||||||
index
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push(&mut self, value: Arg<'b>) -> usize {
|
|
||||||
if self.built {
|
if self.built {
|
||||||
panic!("Cannot add Args to the map after the map is built");
|
panic!("Cannot add Args to the map after the map is built");
|
||||||
}
|
}
|
||||||
|
@ -93,7 +75,7 @@ impl<'b> MKeyMap<'b> {
|
||||||
}
|
}
|
||||||
//TODO ::push_many([x, y])
|
//TODO ::push_many([x, y])
|
||||||
|
|
||||||
pub fn insert_key(&mut self, key: KeyType, index: usize) {
|
pub(crate) fn insert_key(&mut self, key: KeyType, index: usize) {
|
||||||
if index >= self.args.len() {
|
if index >= self.args.len() {
|
||||||
panic!("Index out of bounds");
|
panic!("Index out of bounds");
|
||||||
}
|
}
|
||||||
|
@ -104,7 +86,7 @@ impl<'b> MKeyMap<'b> {
|
||||||
|
|
||||||
// ! Arg mutation functionality
|
// ! Arg mutation functionality
|
||||||
|
|
||||||
pub fn get(&self, key: &KeyType) -> Option<&Arg<'b>> {
|
pub(crate) fn get(&self, key: &KeyType) -> Option<&Arg<'b>> {
|
||||||
self.keys
|
self.keys
|
||||||
.iter()
|
.iter()
|
||||||
.find(|k| k.key == *key)
|
.find(|k| k.key == *key)
|
||||||
|
@ -112,33 +94,11 @@ impl<'b> MKeyMap<'b> {
|
||||||
}
|
}
|
||||||
//TODO ::get_first([KeyA, KeyB])
|
//TODO ::get_first([KeyA, KeyB])
|
||||||
|
|
||||||
pub fn get_mut(&mut self, key: &KeyType) -> Option<&mut Arg<'b>> {
|
pub(crate) fn is_empty(&self) -> bool {
|
||||||
let key = self.keys.iter().find(|k| k.key == *key);
|
|
||||||
|
|
||||||
match key {
|
|
||||||
Some(k) => self.args.get_mut(k.index),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
|
||||||
self.keys.is_empty() && self.args.is_empty()
|
self.keys.is_empty() && self.args.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_key(&mut self, key: &KeyType) {
|
pub(crate) fn _build(&mut self) {
|
||||||
self.keys
|
|
||||||
.iter()
|
|
||||||
.position(|k| k.key == *key)
|
|
||||||
.map(|i| self.keys.swap_remove(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert_key_by_name(&mut self, key: KeyType, name: &str) {
|
|
||||||
let index = self.find_by_name(name);
|
|
||||||
|
|
||||||
self.keys.push(Key { key, index });
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn _build(&mut self) {
|
|
||||||
self.built = true;
|
self.built = true;
|
||||||
|
|
||||||
for (i, arg) in self.args.iter_mut().enumerate() {
|
for (i, arg) in self.args.iter_mut().enumerate() {
|
||||||
|
@ -148,63 +108,11 @@ impl<'b> MKeyMap<'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_entries_by_index(&mut self, index: usize) {
|
|
||||||
let short;
|
|
||||||
let positional;
|
|
||||||
let mut longs: Vec<_>;
|
|
||||||
|
|
||||||
let arg = &self.args[index];
|
|
||||||
short = arg.short.map(KeyType::Short);
|
|
||||||
positional = arg.index.map(KeyType::Position);
|
|
||||||
|
|
||||||
longs = arg
|
|
||||||
.aliases
|
|
||||||
.clone()
|
|
||||||
.map(|v| {
|
|
||||||
v.iter()
|
|
||||||
.map(|(n, _)| KeyType::Long(OsString::from(n)))
|
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.unwrap_or_default();
|
|
||||||
longs.extend(arg.long.map(|l| KeyType::Long(OsString::from(l))));
|
|
||||||
|
|
||||||
if let Some(s) = short {
|
|
||||||
self.insert_key(s, index)
|
|
||||||
}
|
|
||||||
if let Some(p) = positional {
|
|
||||||
self.insert_key(p, index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn find_by_name(&mut self, name: &str) -> usize {
|
|
||||||
self.args
|
|
||||||
.iter()
|
|
||||||
.position(|x| x.name == name)
|
|
||||||
.expect("No such name found")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove(&mut self, key: &KeyType) -> Option<Arg<'b>> {
|
|
||||||
if self.built {
|
|
||||||
panic!("Cannot remove args after being built");
|
|
||||||
}
|
|
||||||
|
|
||||||
let idx = self.keys.iter().position(|k| k.key == *key);
|
|
||||||
|
|
||||||
if let Some(idx) = idx {
|
|
||||||
let arg = self.args.swap_remove(idx);
|
|
||||||
for key in _get_keys(&arg) {
|
|
||||||
self.remove_key(&key);
|
|
||||||
}
|
|
||||||
return Some(arg);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO ::remove_many([KeyA, KeyB])
|
//TODO ::remove_many([KeyA, KeyB])
|
||||||
//? probably shouldn't add a possibility for removal?
|
//? probably shouldn't add a possibility for removal?
|
||||||
//? or remove by replacement by some dummy object, so the order is preserved
|
//? or remove by replacement by some dummy object, so the order is preserved
|
||||||
|
|
||||||
pub fn remove_by_name(&mut self, _name: Id) -> Option<Arg<'b>> {
|
pub(crate) fn remove_by_name(&mut self, _name: Id) -> Option<Arg<'b>> {
|
||||||
if self.built {
|
if self.built {
|
||||||
panic!("Cannot remove args after being built");
|
panic!("Cannot remove args after being built");
|
||||||
}
|
}
|
||||||
|
@ -239,130 +147,3 @@ fn _get_keys(arg: &Arg) -> Vec<KeyType> {
|
||||||
|
|
||||||
keys
|
keys
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use self::KeyType::*;
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn get_some_value() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
|
|
||||||
map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
map.get(&Long(OsString::from("One"))),
|
|
||||||
Some(&Arg::with_name("Value1"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn get_none_value() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
|
|
||||||
map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
map.get(&Long(OsString::from("Two")));
|
|
||||||
|
|
||||||
assert_eq!(map.get(&Long(OsString::from("Two"))), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn insert_delete_value() {
|
|
||||||
// let mut map = MKeyMap::new();
|
|
||||||
// map.insert("One", clap::Arg::with_name("Value1"));
|
|
||||||
// assert_eq!(map.remove("One"), Some(clap::Arg::with_name("Value1")));
|
|
||||||
// assert!(map.is_empty());
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn insert_duplicate_key() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
|
|
||||||
map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
map.insert(Long(OsString::from("One")), Arg::with_name("Value2")),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
// #[should_panic(expected = "Len changed")]
|
|
||||||
fn insert_duplicate_value() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
|
|
||||||
map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
let orig_len = map.args.len();
|
|
||||||
|
|
||||||
map.insert(Long(OsString::from("Two")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
assert_eq!(map.args.len(), orig_len + 1 /* , "Len changed" */);
|
|
||||||
// assert_eq!(
|
|
||||||
// map.get(&Long(OsString::from("One"))),
|
|
||||||
// map.get(&Long(OsString::from("Two")))
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn insert_delete_none() {
|
|
||||||
// let mut map = MKeyMap::new();
|
|
||||||
// map.insert("One", clap::Arg::with_name("Value1"));
|
|
||||||
// assert_eq!(map.remove("Two"), None);
|
|
||||||
// assert!(!map.is_empty());
|
|
||||||
// assert_eq!(map.get("One"), Some(clap::Arg::with_name("Value1")));
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn insert_multiple_keys() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
let index = map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
map.insert_key(Long(OsString::from("Two")), index);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
map.get(&Long(OsString::from("One"))),
|
|
||||||
map.get(&Long(OsString::from("Two")))
|
|
||||||
);
|
|
||||||
assert_eq!(map.args.len(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[test]
|
|
||||||
// fn insert_by_name() {
|
|
||||||
// let mut map: MKeyMap<Arg> = MKeyMap::new();
|
|
||||||
// let index = map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
// map.insert_key_by_name(Long(OsString::from("Two")), "Value1");
|
|
||||||
|
|
||||||
// assert_eq!(
|
|
||||||
// map.get(Long(OsString::from("One"))),
|
|
||||||
// map.get(Long(OsString::from("Two")))
|
|
||||||
// );
|
|
||||||
// assert_eq!(map.values.len(), 1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn get_mutable() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
|
|
||||||
map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
map.get_mut(&Long(OsString::from("One"))),
|
|
||||||
Some(&mut Arg::with_name("Value1"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn remove_key() {
|
|
||||||
let mut map: MKeyMap = MKeyMap::new();
|
|
||||||
let index = map.insert(Long(OsString::from("One")), Arg::with_name("Value1"));
|
|
||||||
|
|
||||||
map.insert_key(Long(OsString::from("Two")), index);
|
|
||||||
map.remove_key(&Long(OsString::from("One")));
|
|
||||||
|
|
||||||
assert_eq!(map.keys.len(), 1);
|
|
||||||
assert_eq!(map.args.len(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ use atty;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
#[doc(hidden)]
|
||||||
pub enum ColorWhen {
|
pub enum ColorWhen {
|
||||||
Auto,
|
Auto,
|
||||||
Always,
|
Always,
|
||||||
|
@ -18,7 +18,7 @@ pub enum ColorWhen {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "color")]
|
#[cfg(feature = "color")]
|
||||||
pub fn is_a_tty(stderr: bool) -> bool {
|
pub(crate) fn is_a_tty(stderr: bool) -> bool {
|
||||||
debugln!("is_a_tty: stderr={:?}", stderr);
|
debugln!("is_a_tty: stderr={:?}", stderr);
|
||||||
let stream = if stderr {
|
let stream = if stderr {
|
||||||
atty::Stream::Stderr
|
atty::Stream::Stderr
|
||||||
|
@ -29,23 +29,21 @@ pub fn is_a_tty(stderr: bool) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "color"))]
|
#[cfg(not(feature = "color"))]
|
||||||
pub fn is_a_tty(_: bool) -> bool {
|
pub(crate) fn is_a_tty(_: bool) -> bool {
|
||||||
debugln!("is_a_tty;");
|
debugln!("is_a_tty;");
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_term_dumb() -> bool {
|
pub(crate) fn is_term_dumb() -> bool {
|
||||||
env::var("TERM").ok() == Some(String::from("dumb"))
|
env::var("TERM").ok() == Some(String::from("dumb"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
pub(crate) struct ColorizerOption {
|
||||||
pub struct ColorizerOption {
|
pub(crate) use_stderr: bool,
|
||||||
pub use_stderr: bool,
|
pub(crate) when: ColorWhen,
|
||||||
pub when: ColorWhen,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
pub(crate) struct Colorizer {
|
||||||
pub struct Colorizer {
|
|
||||||
when: ColorWhen,
|
when: ColorWhen,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +58,7 @@ macro_rules! color {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Colorizer {
|
impl Colorizer {
|
||||||
pub fn new(option: &ColorizerOption) -> Colorizer {
|
pub(crate) fn new(option: &ColorizerOption) -> Colorizer {
|
||||||
let is_a_tty = is_a_tty(option.use_stderr);
|
let is_a_tty = is_a_tty(option.use_stderr);
|
||||||
let is_term_dumb = is_term_dumb();
|
let is_term_dumb = is_term_dumb();
|
||||||
Colorizer {
|
Colorizer {
|
||||||
|
@ -72,7 +70,7 @@ impl Colorizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn good<T>(&self, msg: T) -> Format<T>
|
pub(crate) fn good<T>(&self, msg: T) -> Format<T>
|
||||||
where
|
where
|
||||||
T: fmt::Display + AsRef<str>,
|
T: fmt::Display + AsRef<str>,
|
||||||
{
|
{
|
||||||
|
@ -80,7 +78,7 @@ impl Colorizer {
|
||||||
color!(self, Good, msg)
|
color!(self, Good, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn warning<T>(&self, msg: T) -> Format<T>
|
pub(crate) fn warning<T>(&self, msg: T) -> Format<T>
|
||||||
where
|
where
|
||||||
T: fmt::Display + AsRef<str>,
|
T: fmt::Display + AsRef<str>,
|
||||||
{
|
{
|
||||||
|
@ -88,7 +86,7 @@ impl Colorizer {
|
||||||
color!(self, Warning, msg)
|
color!(self, Warning, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error<T>(&self, msg: T) -> Format<T>
|
pub(crate) fn error<T>(&self, msg: T) -> Format<T>
|
||||||
where
|
where
|
||||||
T: fmt::Display + AsRef<str>,
|
T: fmt::Display + AsRef<str>,
|
||||||
{
|
{
|
||||||
|
@ -96,7 +94,7 @@ impl Colorizer {
|
||||||
color!(self, Error, msg)
|
color!(self, Error, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn none<T>(&self, msg: T) -> Format<T>
|
pub(crate) fn none<T>(&self, msg: T) -> Format<T>
|
||||||
where
|
where
|
||||||
T: fmt::Display + AsRef<str>,
|
T: fmt::Display + AsRef<str>,
|
||||||
{
|
{
|
||||||
|
@ -117,8 +115,7 @@ impl Default for Colorizer {
|
||||||
/// Defines styles for different types of error messages. Defaults to Error=Red, Warning=Yellow,
|
/// Defines styles for different types of error messages. Defaults to Error=Red, Warning=Yellow,
|
||||||
/// and Good=Green
|
/// and Good=Green
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[doc(hidden)]
|
pub(crate) enum Format<T> {
|
||||||
pub enum Format<T> {
|
|
||||||
/// Defines the style used for errors, defaults to Red
|
/// Defines the style used for errors, defaults to Red
|
||||||
Error(T),
|
Error(T),
|
||||||
/// Defines the style used for warnings, defaults to Yellow
|
/// Defines the style used for warnings, defaults to Yellow
|
||||||
|
|
|
@ -22,7 +22,7 @@ use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
#[cfg(not(feature = "wrap_help"))]
|
#[cfg(not(feature = "wrap_help"))]
|
||||||
mod term_size {
|
mod term_size {
|
||||||
pub fn dimensions() -> Option<(usize, usize)> {
|
pub(crate) fn dimensions() -> Option<(usize, usize)> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ const TAB: &str = " ";
|
||||||
/// `clap` Help Writer.
|
/// `clap` Help Writer.
|
||||||
///
|
///
|
||||||
/// Wraps a writer stream providing different methods to generate help for `clap` objects.
|
/// Wraps a writer stream providing different methods to generate help for `clap` objects.
|
||||||
pub struct Help<'b, 'c, 'd, 'w> {
|
pub(crate) struct Help<'b, 'c, 'd, 'w> {
|
||||||
writer: &'w mut dyn Write,
|
writer: &'w mut dyn Write,
|
||||||
parser: &'d Parser<'b, 'c>,
|
parser: &'d Parser<'b, 'c>,
|
||||||
next_line_help: bool,
|
next_line_help: bool,
|
||||||
|
@ -52,7 +52,7 @@ pub struct Help<'b, 'c, 'd, 'w> {
|
||||||
// Public Functions
|
// Public Functions
|
||||||
impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
/// Create a new `Help` instance.
|
/// Create a new `Help` instance.
|
||||||
pub fn new(
|
pub(crate) fn new(
|
||||||
w: &'w mut dyn Write,
|
w: &'w mut dyn Write,
|
||||||
parser: &'d Parser<'b, 'c>,
|
parser: &'d Parser<'b, 'c>,
|
||||||
use_long: bool,
|
use_long: bool,
|
||||||
|
@ -92,7 +92,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the parser help to the wrapped stream.
|
/// Writes the parser help to the wrapped stream.
|
||||||
pub fn write_help(&mut self) -> ClapResult<()> {
|
pub(crate) fn write_help(&mut self) -> ClapResult<()> {
|
||||||
debugln!("Help::write_help;");
|
debugln!("Help::write_help;");
|
||||||
if let Some(h) = self.parser.app.help_str {
|
if let Some(h) = self.parser.app.help_str {
|
||||||
write!(self.writer, "{}", h).map_err(Error::from)?;
|
write!(self.writer, "{}", h).map_err(Error::from)?;
|
||||||
|
@ -639,7 +639,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
/// Writes help for all arguments (options, flags, args, subcommands)
|
/// Writes help for all arguments (options, flags, args, subcommands)
|
||||||
/// including titles of a Parser Object to the wrapped stream.
|
/// including titles of a Parser Object to the wrapped stream.
|
||||||
pub fn write_all_args(&mut self) -> ClapResult<()> {
|
pub(crate) fn write_all_args(&mut self) -> ClapResult<()> {
|
||||||
debugln!("Help::write_all_args;");
|
debugln!("Help::write_all_args;");
|
||||||
let flags = self.parser.has_flags();
|
let flags = self.parser.has_flags();
|
||||||
// Strange filter/count vs fold... https://github.com/rust-lang/rust/issues/33038
|
// Strange filter/count vs fold... https://github.com/rust-lang/rust/issues/33038
|
||||||
|
@ -804,7 +804,7 @@ impl<'b, 'c, 'd, 'w> Help<'b, 'c, 'd, 'w> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes default help for a Parser Object to the wrapped stream.
|
/// Writes default help for a Parser Object to the wrapped stream.
|
||||||
pub fn write_default_help(&mut self) -> ClapResult<()> {
|
pub(crate) fn write_default_help(&mut self) -> ClapResult<()> {
|
||||||
debugln!("Help::write_default_help;");
|
debugln!("Help::write_default_help;");
|
||||||
if let Some(h) = self.parser.app.pre_help {
|
if let Some(h) = self.parser.app.pre_help {
|
||||||
self.write_before_after_help(h)?;
|
self.write_before_after_help(h)?;
|
||||||
|
|
|
@ -3,5 +3,5 @@ mod usage;
|
||||||
|
|
||||||
pub mod fmt;
|
pub mod fmt;
|
||||||
|
|
||||||
pub use self::help::Help;
|
pub(crate) use self::help::Help;
|
||||||
pub use self::usage::Usage;
|
pub(crate) use self::usage::Usage;
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::INTERNAL_ERROR_MSG;
|
||||||
|
|
||||||
type Id = u64;
|
type Id = u64;
|
||||||
|
|
||||||
pub struct Usage<'b, 'c, 'z>
|
pub(crate) struct Usage<'b, 'c, 'z>
|
||||||
where
|
where
|
||||||
'b: 'c,
|
'b: 'c,
|
||||||
'c: 'z,
|
'c: 'z,
|
||||||
|
@ -18,13 +18,13 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, 'c, 'z> Usage<'b, 'c, 'z> {
|
impl<'b, 'c, 'z> Usage<'b, 'c, 'z> {
|
||||||
pub fn new(p: &'z Parser<'b, 'c>) -> Self {
|
pub(crate) fn new(p: &'z Parser<'b, 'c>) -> Self {
|
||||||
Usage { p }
|
Usage { p }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a usage string for display. This happens just after all arguments were parsed, but before
|
// Creates a usage string for display. This happens just after all arguments were parsed, but before
|
||||||
// any subcommands have been parsed (so as to give subcommands their own usage recursively)
|
// any subcommands have been parsed (so as to give subcommands their own usage recursively)
|
||||||
pub fn create_usage_with_title(&self, used: &[Id]) -> String {
|
pub(crate) fn create_usage_with_title(&self, used: &[Id]) -> String {
|
||||||
debugln!("usage::create_usage_with_title;");
|
debugln!("usage::create_usage_with_title;");
|
||||||
let mut usage = String::with_capacity(75);
|
let mut usage = String::with_capacity(75);
|
||||||
usage.push_str("USAGE:\n ");
|
usage.push_str("USAGE:\n ");
|
||||||
|
@ -33,7 +33,7 @@ impl<'b, 'c, 'z> Usage<'b, 'c, 'z> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a usage string (*without title*) if one was not provided by the user manually.
|
// Creates a usage string (*without title*) if one was not provided by the user manually.
|
||||||
pub fn create_usage_no_title(&self, used: &[Id]) -> String {
|
pub(crate) fn create_usage_no_title(&self, used: &[Id]) -> String {
|
||||||
debugln!("usage::create_usage_no_title;");
|
debugln!("usage::create_usage_no_title;");
|
||||||
if let Some(u) = self.p.app.usage_str {
|
if let Some(u) = self.p.app.usage_str {
|
||||||
String::from(&*u)
|
String::from(&*u)
|
||||||
|
@ -45,7 +45,7 @@ impl<'b, 'c, 'z> Usage<'b, 'c, 'z> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a usage string for display in help messages (i.e. not for errors)
|
// Creates a usage string for display in help messages (i.e. not for errors)
|
||||||
pub fn create_help_usage(&self, incl_reqs: bool) -> String {
|
pub(crate) fn create_help_usage(&self, incl_reqs: bool) -> String {
|
||||||
debugln!("Usage::create_help_usage; incl_reqs={:?}", incl_reqs);
|
debugln!("Usage::create_help_usage; incl_reqs={:?}", incl_reqs);
|
||||||
let mut usage = String::with_capacity(75);
|
let mut usage = String::with_capacity(75);
|
||||||
let name = self
|
let name = self
|
||||||
|
@ -310,7 +310,7 @@ impl<'b, 'c, 'z> Usage<'b, 'c, 'z> {
|
||||||
// `incl_last`: should we incldue args that are Arg::Last? (i.e. `prog [foo] -- [last]). We
|
// `incl_last`: should we incldue args that are Arg::Last? (i.e. `prog [foo] -- [last]). We
|
||||||
// can't do that for required usages being built for subcommands because it would look like:
|
// can't do that for required usages being built for subcommands because it would look like:
|
||||||
// `prog [foo] -- [last] <subcommand>` which is totally wrong.
|
// `prog [foo] -- [last] <subcommand>` which is totally wrong.
|
||||||
pub fn get_required_usage_from(
|
pub(crate) fn get_required_usage_from(
|
||||||
&self,
|
&self,
|
||||||
incls: &[Id],
|
incls: &[Id],
|
||||||
matcher: Option<&ArgMatcher>,
|
matcher: Option<&ArgMatcher>,
|
||||||
|
|
|
@ -11,8 +11,7 @@ use crate::build::app::Propagation;
|
||||||
use crate::build::AppSettings as AS;
|
use crate::build::AppSettings as AS;
|
||||||
use crate::build::{App, Arg, ArgSettings};
|
use crate::build::{App, Arg, ArgSettings};
|
||||||
use crate::mkeymap::KeyType;
|
use crate::mkeymap::KeyType;
|
||||||
use crate::output::Help;
|
use crate::output::{Help, Usage};
|
||||||
use crate::output::Usage;
|
|
||||||
use crate::parse::errors::Error as ClapError;
|
use crate::parse::errors::Error as ClapError;
|
||||||
use crate::parse::errors::ErrorKind;
|
use crate::parse::errors::ErrorKind;
|
||||||
use crate::parse::errors::Result as ClapResult;
|
use crate::parse::errors::Result as ClapResult;
|
||||||
|
|
Loading…
Reference in a new issue