mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
Merge pull request #1296 from kbknapp/v3-dev
refactor(Modules): moves the modules around into a more logical order…
This commit is contained in:
commit
05c8ab8646
35 changed files with 127 additions and 108 deletions
|
@ -1,17 +0,0 @@
|
|||
pub use self::arg::Arg;
|
||||
pub use self::arg_matcher::ArgMatcher;
|
||||
pub use self::arg_matches::{ArgMatches, OsValues, Values};
|
||||
pub use self::group::ArgGroup;
|
||||
pub use self::matched_arg::MatchedArg;
|
||||
pub use self::settings::{ArgFlags, ArgSettings};
|
||||
pub use self::subcommand::SubCommand;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod arg;
|
||||
mod arg_matches;
|
||||
mod arg_matcher;
|
||||
mod subcommand;
|
||||
mod matched_arg;
|
||||
mod group;
|
||||
pub mod settings;
|
|
@ -1,8 +1,5 @@
|
|||
mod settings;
|
||||
pub mod parser;
|
||||
mod help;
|
||||
mod validator;
|
||||
mod usage;
|
||||
pub use self::settings::{AppFlags, AppSettings};
|
||||
|
||||
// Std
|
||||
use std::env;
|
||||
|
@ -19,14 +16,12 @@ use std::iter::Peekable;
|
|||
use yaml_rust::Yaml;
|
||||
|
||||
// Internal
|
||||
use app::parser::Parser;
|
||||
use app::help::Help;
|
||||
use args::{Arg, ArgGroup, ArgMatcher, ArgMatches};
|
||||
use args::settings::ArgSettings;
|
||||
use errors::Result as ClapResult;
|
||||
pub use self::settings::{AppFlags, AppSettings};
|
||||
use build::{Arg, ArgGroup, ArgSettings};
|
||||
use completions::{ComplGen, Shell};
|
||||
use fmt::ColorWhen;
|
||||
use output::Help;
|
||||
use output::fmt::ColorWhen;
|
||||
use parse::{Parser, ArgMatcher, ArgMatches};
|
||||
use parse::errors::Result as ClapResult;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
|
@ -116,9 +111,9 @@ where
|
|||
#[doc(hidden)]
|
||||
pub groups: Vec<ArgGroup<'a>>,
|
||||
#[doc(hidden)]
|
||||
help_short: Option<char>,
|
||||
pub help_short: Option<char>,
|
||||
#[doc(hidden)]
|
||||
version_short: Option<char>,
|
||||
pub version_short: Option<char>,
|
||||
#[doc(hidden)]
|
||||
pub help_message: Option<&'a str>,
|
||||
#[doc(hidden)]
|
||||
|
@ -1409,7 +1404,7 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
Ok(matcher.into())
|
||||
}
|
||||
|
||||
fn _build(&mut self, prop: Propagation) {
|
||||
pub(crate) fn _build(&mut self, prop: Propagation) {
|
||||
debugln!("App::_build;");
|
||||
// Make sure all the globally set flags apply to us as well
|
||||
self.settings = self.settings | self.g_settings;
|
||||
|
@ -1709,9 +1704,9 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
ColorWhen::Auto
|
||||
}
|
||||
}
|
||||
fn contains_long(&self, l: &str) -> bool { longs!(self).any(|al| al == l) }
|
||||
pub(crate) fn contains_long(&self, l: &str) -> bool { longs!(self).any(|al| al == l) }
|
||||
|
||||
fn contains_short(&self, s: char) -> bool { shorts!(self).any(|arg_s| arg_s == s) }
|
||||
pub(crate) fn contains_short(&self, s: char) -> bool { shorts!(self).any(|arg_s| arg_s == s) }
|
||||
|
||||
pub fn is_set(&self, s: AppSettings) -> bool {
|
||||
self.settings.is_set(s) || self.g_settings.is_set(s)
|
|
@ -1,3 +1,9 @@
|
|||
#[macro_use]
|
||||
mod macros;
|
||||
mod settings;
|
||||
pub use self::settings::{ArgFlags, ArgSettings};
|
||||
|
||||
// Std
|
||||
#[cfg(feature = "yaml")]
|
||||
use std::collections::BTreeMap;
|
||||
use std::rc::Rc;
|
||||
|
@ -12,12 +18,13 @@ use std::env;
|
|||
use std::cmp::{Ord, Ordering};
|
||||
use std::str;
|
||||
|
||||
// Third Party
|
||||
#[cfg(feature = "yaml")]
|
||||
use yaml_rust::Yaml;
|
||||
use map::VecMap;
|
||||
use util::VecMap;
|
||||
|
||||
use usage_parser::UsageParser;
|
||||
use args::settings::{ArgFlags, ArgSettings};
|
||||
// Internal
|
||||
use build::UsageParser;
|
||||
use INTERNAL_ERROR_MSG;
|
||||
|
||||
/// The abstract representation of a command line argument. Used to set all the options and
|
||||
|
@ -4239,8 +4246,8 @@ impl<'n, 'e> fmt::Debug for Arg<'n, 'e> {
|
|||
// Flags
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use map::VecMap;
|
||||
use args::settings::ArgSettings;
|
||||
use util::VecMap;
|
||||
use build::ArgSettings;
|
||||
use super::Arg;
|
||||
|
||||
#[test]
|
|
@ -1,7 +1,9 @@
|
|||
// Std
|
||||
#[cfg(feature = "yaml")]
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::{Debug, Formatter, Result};
|
||||
|
||||
// Third Party
|
||||
#[cfg(feature = "yaml")]
|
||||
use yaml_rust::Yaml;
|
||||
|
10
src/build/mod.rs
Normal file
10
src/build/mod.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
pub mod app;
|
||||
pub mod arg;
|
||||
|
||||
mod arg_group;
|
||||
mod usage_parser;
|
||||
|
||||
pub use self::usage_parser::UsageParser;
|
||||
pub use self::app::{App, AppFlags, AppSettings, Propagation};
|
||||
pub use self::arg::{Arg, ArgFlags, ArgSettings};
|
||||
pub use self::arg_group::ArgGroup;
|
|
@ -1,8 +1,7 @@
|
|||
// Internal
|
||||
use INTERNAL_ERROR_MSG;
|
||||
use args::Arg;
|
||||
use args::settings::ArgSettings;
|
||||
use map::VecMap;
|
||||
use build::{Arg, ArgSettings};
|
||||
use util::VecMap;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum UsageToken {
|
||||
|
@ -216,8 +215,7 @@ fn help_start(b: u8) -> bool { b != b'\'' }
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use args::Arg;
|
||||
use args::ArgSettings;
|
||||
use build::{Arg, ArgSettings};
|
||||
|
||||
#[test]
|
||||
fn create_flag_usage() {
|
|
@ -2,8 +2,7 @@
|
|||
use std::io::Write;
|
||||
|
||||
// Internal
|
||||
use app::App;
|
||||
use args::Arg;
|
||||
use build::{App, Arg};
|
||||
use completions;
|
||||
|
||||
pub struct BashGen<'a, 'b>(&'b App<'a, 'b>)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use std::io::Write;
|
||||
|
||||
// Internal
|
||||
use app::App;
|
||||
use build::App;
|
||||
|
||||
pub struct FishGen<'a, 'b>(&'b App<'a, 'b>)
|
||||
where
|
||||
|
|
|
@ -10,7 +10,7 @@ mod shell;
|
|||
use std::io::Write;
|
||||
|
||||
// Internal
|
||||
use app::App;
|
||||
use build::App;
|
||||
use self::bash::BashGen;
|
||||
use self::fish::FishGen;
|
||||
use self::zsh::ZshGen;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use std::io::Write;
|
||||
|
||||
// Internal
|
||||
use app::App;
|
||||
use build::App;
|
||||
use INTERNAL_ERROR_MSG;
|
||||
|
||||
pub struct PowerShellGen<'a, 'b>(&'b App<'a, 'b>)
|
||||
|
|
|
@ -4,8 +4,7 @@ use std::io::Write;
|
|||
use std::ascii::AsciiExt;
|
||||
|
||||
// Internal
|
||||
use app::App;
|
||||
use args::ArgSettings;
|
||||
use build::{App, ArgSettings};
|
||||
use completions;
|
||||
use INTERNAL_ERROR_MSG;
|
||||
|
||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -550,24 +550,19 @@ extern crate yaml_rust;
|
|||
|
||||
#[cfg(feature = "yaml")]
|
||||
pub use yaml_rust::YamlLoader;
|
||||
pub use args::{Arg, ArgGroup, ArgMatches, ArgSettings, OsValues, SubCommand, Values};
|
||||
pub use app::{App, AppSettings, Propagation};
|
||||
pub use fmt::Format;
|
||||
pub use errors::{Error, ErrorKind, Result};
|
||||
pub use build::{Arg, ArgGroup, ArgSettings, App, AppSettings, Propagation};
|
||||
pub use parse::{OsValues, SubCommand, Values, ArgMatches};
|
||||
pub use output::fmt::Format;
|
||||
pub use parse::errors::{Error, ErrorKind, Result};
|
||||
pub use completions::Shell;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod app;
|
||||
mod args;
|
||||
mod usage_parser;
|
||||
mod fmt;
|
||||
mod suggestions;
|
||||
mod errors;
|
||||
mod osstringext;
|
||||
mod strext;
|
||||
mod completions;
|
||||
mod map;
|
||||
mod parse;
|
||||
mod build;
|
||||
mod util;
|
||||
mod output;
|
||||
|
||||
const INTERNAL_ERROR_MSG: &'static str = "Fatal internal error. Please consider filing a bug \
|
||||
report at https://github.com/kbknapp/clap-rs/issues";
|
||||
|
|
|
@ -889,7 +889,7 @@ macro_rules! args_mut {
|
|||
macro_rules! flags {
|
||||
($app:expr, $how:ident) => {
|
||||
$app.args.$how()
|
||||
.filter(|a| !a.settings.is_set(::args::settings::ArgSettings::TakesValue))
|
||||
.filter(|a| !a.settings.is_set(::build::ArgSettings::TakesValue))
|
||||
.filter(|a| a.short.is_some() || a.long.is_some())
|
||||
.filter(|a| !a.help_heading.is_some())
|
||||
};
|
||||
|
@ -908,7 +908,7 @@ macro_rules! flags_mut {
|
|||
macro_rules! opts {
|
||||
($app:expr, $how:ident) => {
|
||||
$app.args.$how()
|
||||
.filter(|a| a.settings.is_set(::args::settings::ArgSettings::TakesValue))
|
||||
.filter(|a| a.settings.is_set(::build::ArgSettings::TakesValue))
|
||||
.filter(|a| a.short.is_some() || a.long.is_some())
|
||||
.filter(|a| !a.help_heading.is_some())
|
||||
};
|
||||
|
|
|
@ -6,13 +6,12 @@ use std::io::{self, Cursor, Read, Write};
|
|||
use std::usize;
|
||||
|
||||
// Internal
|
||||
use app::{App, AppSettings};
|
||||
use app::parser::Parser;
|
||||
use args::{Arg, ArgSettings};
|
||||
use errors::{Error, Result as ClapResult};
|
||||
use fmt::{Colorizer, ColorizerOption, Format};
|
||||
use app::usage::Usage;
|
||||
use map::VecMap;
|
||||
use build::{App, AppSettings, Arg, ArgSettings};
|
||||
use parse::Parser;
|
||||
use parse::errors::{Error, Result as ClapResult};
|
||||
use output::fmt::{Colorizer, ColorizerOption, Format};
|
||||
use output::Usage;
|
||||
use util::VecMap;
|
||||
use INTERNAL_ERROR_MSG;
|
||||
|
||||
// Third Party
|
7
src/output/mod.rs
Normal file
7
src/output/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
mod help;
|
||||
mod usage;
|
||||
|
||||
pub mod fmt;
|
||||
|
||||
pub use self::help::Help;
|
||||
pub use self::usage::Usage;
|
|
@ -3,10 +3,9 @@ use std::collections::{BTreeMap, VecDeque};
|
|||
|
||||
// Internal
|
||||
use INTERNAL_ERROR_MSG;
|
||||
use args::{Arg, ArgMatcher};
|
||||
use args::settings::ArgSettings;
|
||||
use app::settings::AppSettings as AS;
|
||||
use app::parser::Parser;
|
||||
use build::{Arg, ArgSettings};
|
||||
use build::AppSettings as AS;
|
||||
use parse::{Parser, ArgMatcher};
|
||||
|
||||
pub struct Usage<'a, 'b, 'c, 'z>(&'z Parser<'a, 'b, 'c>)
|
||||
where
|
|
@ -7,8 +7,8 @@ use std::mem;
|
|||
use indexmap;
|
||||
|
||||
// Internal
|
||||
use args::{Arg, ArgMatches, MatchedArg, SubCommand};
|
||||
use args::settings::ArgSettings;
|
||||
use build::{Arg, ArgSettings};
|
||||
use parse::{ArgMatches, MatchedArg, SubCommand};
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
|
@ -8,9 +8,9 @@ use std::process;
|
|||
use std::result::Result as StdResult;
|
||||
|
||||
// Internal
|
||||
use args::Arg;
|
||||
use fmt::{ColorWhen, Colorizer, ColorizerOption};
|
||||
use suggestions;
|
||||
use build::Arg;
|
||||
use output::fmt::{ColorWhen, Colorizer, ColorizerOption};
|
||||
use parse::features::suggestions;
|
||||
|
||||
/// Short hand for [`Result`] type
|
||||
///
|
1
src/parse/features/mod.rs
Normal file
1
src/parse/features/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod suggestions;
|
|
@ -3,8 +3,8 @@
|
|||
use strsim;
|
||||
|
||||
// Internal
|
||||
use fmt::Format;
|
||||
use app::App;
|
||||
use build::App;
|
||||
use output::fmt::Format;
|
||||
|
||||
/// Produces a string from a given list of possible values which is similar to
|
||||
/// the passed in value `v` with a certain confidence.
|
|
@ -9,8 +9,7 @@ use indexmap::IndexMap;
|
|||
|
||||
// Internal
|
||||
use INVALID_UTF8;
|
||||
use args::MatchedArg;
|
||||
use args::SubCommand;
|
||||
use parse::{MatchedArg, SubCommand};
|
||||
|
||||
/// Used to get information about the arguments that where supplied to the program at runtime by
|
||||
/// the user. New instances of this struct are obtained by using the [`App::get_matches`] family of
|
7
src/parse/matches/mod.rs
Normal file
7
src/parse/matches/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
mod arg_matches;
|
||||
mod matched_arg;
|
||||
mod subcommand;
|
||||
|
||||
pub use self::arg_matches::{ArgMatches, Values, OsValues};
|
||||
pub use self::subcommand::SubCommand;
|
||||
pub use self::matched_arg::MatchedArg;
|
13
src/parse/mod.rs
Normal file
13
src/parse/mod.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
pub mod errors;
|
||||
pub mod features;
|
||||
|
||||
mod matches;
|
||||
mod arg_matcher;
|
||||
mod parser;
|
||||
mod validator;
|
||||
|
||||
pub use self::parser::{Parser, ParseResult};
|
||||
pub use self::matches::ArgMatches;
|
||||
pub use self::arg_matcher::ArgMatcher;
|
||||
pub use self::matches::{Values, OsValues, SubCommand, MatchedArg};
|
||||
pub use self::validator::Validator;
|
|
@ -11,25 +11,23 @@ use std::mem;
|
|||
use std::cell::Cell;
|
||||
|
||||
// Third party facade
|
||||
use map::VecMap;
|
||||
use util::VecMap;
|
||||
|
||||
// Internal
|
||||
use INTERNAL_ERROR_MSG;
|
||||
use INVALID_UTF8;
|
||||
use SubCommand;
|
||||
use app::App;
|
||||
use app::help::Help;
|
||||
use args::{Arg, ArgMatcher};
|
||||
use args::settings::ArgSettings;
|
||||
use errors::ErrorKind;
|
||||
use errors::Error as ClapError;
|
||||
use errors::Result as ClapResult;
|
||||
use osstringext::OsStrExt2;
|
||||
use suggestions;
|
||||
use app::settings::AppSettings as AS;
|
||||
use app::validator::Validator;
|
||||
use app::usage::Usage;
|
||||
use app::Propagation;
|
||||
use build::{App, Arg, ArgSettings};
|
||||
use build::app::Propagation;
|
||||
use build::AppSettings as AS;
|
||||
use parse::{ArgMatcher, SubCommand};
|
||||
use output::Help;
|
||||
use parse::errors::ErrorKind;
|
||||
use parse::errors::Error as ClapError;
|
||||
use parse::errors::Result as ClapResult;
|
||||
use parse::Validator;
|
||||
use util::OsStrExt2;
|
||||
use parse::features::suggestions;
|
||||
use output::Usage;
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
#[doc(hidden)]
|
|
@ -5,14 +5,13 @@ use std::ascii::AsciiExt;
|
|||
// Internal
|
||||
use INTERNAL_ERROR_MSG;
|
||||
use INVALID_UTF8;
|
||||
use args::{Arg, ArgMatcher, MatchedArg};
|
||||
use args::settings::ArgSettings;
|
||||
use errors::{Error, ErrorKind};
|
||||
use errors::Result as ClapResult;
|
||||
use app::settings::AppSettings as AS;
|
||||
use app::parser::{ParseResult, Parser};
|
||||
use fmt::{Colorizer, ColorizerOption};
|
||||
use app::usage::Usage;
|
||||
use build::{Arg, ArgSettings};
|
||||
use build::app::AppSettings as AS;
|
||||
use parse::{ArgMatcher, MatchedArg, ParseResult, Parser};
|
||||
use parse::errors::{Error, ErrorKind};
|
||||
use parse::errors::Result as ClapResult;
|
||||
use output::fmt::{Colorizer, ColorizerOption};
|
||||
use output::Usage;
|
||||
|
||||
pub struct Validator<'a, 'b, 'c, 'z>(&'z mut Parser<'a, 'b, 'c>)
|
||||
where
|
9
src/util/mod.rs
Normal file
9
src/util/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
mod map;
|
||||
mod osstringext;
|
||||
mod strext;
|
||||
|
||||
pub use self::map::{Values, VecMap};
|
||||
pub use self::osstringext::OsStrExt2;
|
||||
#[cfg(any(target_os = "windows", target_arch = "wasm32"))]
|
||||
pub use self::osstringext::OsStrExt3;
|
||||
pub use self::strext::_StrExt;
|
Loading…
Reference in a new issue