diff --git a/src/args/mod.rs b/src/args/mod.rs deleted file mode 100644 index a79f4b84..00000000 --- a/src/args/mod.rs +++ /dev/null @@ -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; diff --git a/src/app/mod.rs b/src/build/app/mod.rs similarity index 99% rename from src/app/mod.rs rename to src/build/app/mod.rs index 48f001ec..59937121 100644 --- a/src/app/mod.rs +++ b/src/build/app/mod.rs @@ -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>, #[doc(hidden)] - help_short: Option, + pub help_short: Option, #[doc(hidden)] - version_short: Option, + pub version_short: Option, #[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) diff --git a/src/app/settings.rs b/src/build/app/settings.rs similarity index 100% rename from src/app/settings.rs rename to src/build/app/settings.rs diff --git a/src/args/macros.rs b/src/build/arg/macros.rs similarity index 100% rename from src/args/macros.rs rename to src/build/arg/macros.rs diff --git a/src/args/arg.rs b/src/build/arg/mod.rs similarity index 99% rename from src/args/arg.rs rename to src/build/arg/mod.rs index d87f7775..6020b925 100644 --- a/src/args/arg.rs +++ b/src/build/arg/mod.rs @@ -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] diff --git a/src/args/settings.rs b/src/build/arg/settings.rs similarity index 100% rename from src/args/settings.rs rename to src/build/arg/settings.rs diff --git a/src/args/group.rs b/src/build/arg_group/mod.rs similarity index 99% rename from src/args/group.rs rename to src/build/arg_group/mod.rs index f39b587c..9f517fd4 100644 --- a/src/args/group.rs +++ b/src/build/arg_group/mod.rs @@ -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; diff --git a/src/build/mod.rs b/src/build/mod.rs new file mode 100644 index 00000000..6ad2fc04 --- /dev/null +++ b/src/build/mod.rs @@ -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; \ No newline at end of file diff --git a/src/usage_parser.rs b/src/build/usage_parser.rs similarity index 99% rename from src/usage_parser.rs rename to src/build/usage_parser.rs index 1c1e2120..332cf802 100644 --- a/src/usage_parser.rs +++ b/src/build/usage_parser.rs @@ -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() { diff --git a/src/completions/bash.rs b/src/completions/bash.rs index c3db11e4..4479ea42 100644 --- a/src/completions/bash.rs +++ b/src/completions/bash.rs @@ -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>) diff --git a/src/completions/fish.rs b/src/completions/fish.rs index e90cfc59..9103a9c5 100644 --- a/src/completions/fish.rs +++ b/src/completions/fish.rs @@ -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 diff --git a/src/completions/mod.rs b/src/completions/mod.rs index 1f1ca903..febc9f9e 100644 --- a/src/completions/mod.rs +++ b/src/completions/mod.rs @@ -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; diff --git a/src/completions/powershell.rs b/src/completions/powershell.rs index e11f9846..45a85cb0 100644 --- a/src/completions/powershell.rs +++ b/src/completions/powershell.rs @@ -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>) diff --git a/src/completions/zsh.rs b/src/completions/zsh.rs index 89e13e1d..d6299921 100644 --- a/src/completions/zsh.rs +++ b/src/completions/zsh.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index 8bba431a..5a5d4a1f 100644 --- a/src/lib.rs +++ b/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"; diff --git a/src/macros.rs b/src/macros.rs index 69c3a8f3..5f521584 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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()) }; diff --git a/src/fmt.rs b/src/output/fmt.rs similarity index 100% rename from src/fmt.rs rename to src/output/fmt.rs diff --git a/src/app/help.rs b/src/output/help.rs similarity index 99% rename from src/app/help.rs rename to src/output/help.rs index 0ea272df..c30ebd90 100644 --- a/src/app/help.rs +++ b/src/output/help.rs @@ -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 diff --git a/src/output/mod.rs b/src/output/mod.rs new file mode 100644 index 00000000..3b0b6d38 --- /dev/null +++ b/src/output/mod.rs @@ -0,0 +1,7 @@ +mod help; +mod usage; + +pub mod fmt; + +pub use self::help::Help; +pub use self::usage::Usage; \ No newline at end of file diff --git a/src/app/usage.rs b/src/output/usage.rs similarity index 99% rename from src/app/usage.rs rename to src/output/usage.rs index c2f66ea5..7770d1ae 100644 --- a/src/app/usage.rs +++ b/src/output/usage.rs @@ -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 diff --git a/src/args/arg_matcher.rs b/src/parse/arg_matcher.rs similarity index 98% rename from src/args/arg_matcher.rs rename to src/parse/arg_matcher.rs index f5e301ff..9fdfed90 100644 --- a/src/args/arg_matcher.rs +++ b/src/parse/arg_matcher.rs @@ -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)] diff --git a/src/errors.rs b/src/parse/errors.rs similarity index 99% rename from src/errors.rs rename to src/parse/errors.rs index 9e6008d2..82f02f28 100644 --- a/src/errors.rs +++ b/src/parse/errors.rs @@ -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 /// diff --git a/src/parse/features/mod.rs b/src/parse/features/mod.rs new file mode 100644 index 00000000..2cabee83 --- /dev/null +++ b/src/parse/features/mod.rs @@ -0,0 +1 @@ +pub mod suggestions; \ No newline at end of file diff --git a/src/suggestions.rs b/src/parse/features/suggestions.rs similarity index 98% rename from src/suggestions.rs rename to src/parse/features/suggestions.rs index acca15ab..491a7567 100644 --- a/src/suggestions.rs +++ b/src/parse/features/suggestions.rs @@ -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. diff --git a/src/args/arg_matches.rs b/src/parse/matches/arg_matches.rs similarity index 99% rename from src/args/arg_matches.rs rename to src/parse/matches/arg_matches.rs index 17ec4d17..17523d22 100644 --- a/src/args/arg_matches.rs +++ b/src/parse/matches/arg_matches.rs @@ -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 diff --git a/src/args/matched_arg.rs b/src/parse/matches/matched_arg.rs similarity index 100% rename from src/args/matched_arg.rs rename to src/parse/matches/matched_arg.rs diff --git a/src/parse/matches/mod.rs b/src/parse/matches/mod.rs new file mode 100644 index 00000000..51b71a5f --- /dev/null +++ b/src/parse/matches/mod.rs @@ -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; \ No newline at end of file diff --git a/src/args/subcommand.rs b/src/parse/matches/subcommand.rs similarity index 100% rename from src/args/subcommand.rs rename to src/parse/matches/subcommand.rs diff --git a/src/parse/mod.rs b/src/parse/mod.rs new file mode 100644 index 00000000..03d81559 --- /dev/null +++ b/src/parse/mod.rs @@ -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; \ No newline at end of file diff --git a/src/app/parser.rs b/src/parse/parser.rs similarity index 99% rename from src/app/parser.rs rename to src/parse/parser.rs index a4f28618..dd8ed35a 100644 --- a/src/app/parser.rs +++ b/src/parse/parser.rs @@ -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)] diff --git a/src/app/validator.rs b/src/parse/validator.rs similarity index 98% rename from src/app/validator.rs rename to src/parse/validator.rs index deef95b7..5bc45c5c 100644 --- a/src/app/validator.rs +++ b/src/parse/validator.rs @@ -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 diff --git a/src/map.rs b/src/util/map.rs similarity index 100% rename from src/map.rs rename to src/util/map.rs diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 00000000..9c51e9ac --- /dev/null +++ b/src/util/mod.rs @@ -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; \ No newline at end of file diff --git a/src/osstringext.rs b/src/util/osstringext.rs similarity index 100% rename from src/osstringext.rs rename to src/util/osstringext.rs diff --git a/src/strext.rs b/src/util/strext.rs similarity index 100% rename from src/strext.rs rename to src/util/strext.rs