Skip to content

Commit

Permalink
Merge pull request clap-rs#3724 from epage/pub
Browse files Browse the repository at this point in the history
feat: Expose builder/parser modules
  • Loading branch information
epage committed May 12, 2022
2 parents 524e36c + 17c99d2 commit 02b4fed
Show file tree
Hide file tree
Showing 30 changed files with 82 additions and 81 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/build/arg.rs → src/builder/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ use std::{env, ffi::OsString};
use yaml_rust::Yaml;

// Internal
use crate::build::usage_parser::UsageParser;
use crate::build::ArgPredicate;
use crate::builder::usage_parser::UsageParser;
use crate::builder::ArgPredicate;
use crate::util::{Id, Key};
use crate::PossibleValue;
use crate::ValueHint;
use crate::INTERNAL_ERROR_MSG;
use crate::{ArgFlags, ArgSettings};

#[cfg(feature = "regex")]
use crate::build::RegexRef;
use crate::builder::RegexRef;

/// The abstract representation of a command line argument. Used to set all the options and
/// relationships that define a valid argument for the program.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions src/build/command.rs → src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ use std::path::Path;
use yaml_rust::Yaml;

// Internal
use crate::build::app_settings::{AppFlags, AppSettings};
use crate::build::arg_settings::ArgSettings;
use crate::build::{arg::ArgProvider, Arg, ArgGroup, ArgPredicate};
use crate::builder::app_settings::{AppFlags, AppSettings};
use crate::builder::arg_settings::ArgSettings;
use crate::builder::{arg::ArgProvider, Arg, ArgGroup, ArgPredicate};
use crate::error::ErrorKind;
use crate::error::Result as ClapResult;
use crate::mkeymap::MKeyMap;
use crate::output::fmt::Stream;
use crate::output::{fmt::Colorizer, Help, HelpWriter, Usage};
use crate::parse::{ArgMatcher, ArgMatches, Parser};
use crate::parser::{ArgMatcher, ArgMatches, Parser};
use crate::util::ChildGraph;
use crate::util::{color::ColorChoice, Id, Key};
use crate::PossibleValue;
use crate::{Error, INTERNAL_ERROR_MSG};

#[cfg(debug_assertions)]
use crate::build::debug_asserts::assert_app;
use crate::builder::debug_asserts::assert_app;

/// Build a command-line interface.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cmp::Ordering;

use clap_lex::RawOsStr;

use crate::build::arg::ArgProvider;
use crate::builder::arg::ArgProvider;
use crate::mkeymap::KeyType;
use crate::util::Id;
use crate::{AppSettings, Arg, Command, ValueHint};
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/build/mod.rs → src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Define [`Command`] line [arguments][`Arg`]

#[macro_use]
mod macros;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions src/build/usage_parser.rs → src/builder/usage_parser.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![allow(deprecated)]

// Internal
use crate::{
build::{Arg, ArgSettings},
INTERNAL_ERROR_MSG,
};
use crate::builder::Arg;
use crate::builder::ArgSettings;
use crate::INTERNAL_ERROR_MSG;

#[derive(PartialEq, Debug)]
enum UsageToken {
Expand Down Expand Up @@ -245,7 +244,7 @@ fn default_value_end(b: u8) -> bool {
mod test {
#![allow(deprecated)]

use crate::build::{Arg, ArgSettings};
use crate::builder::{Arg, ArgSettings};

#[allow(clippy::cognitive_complexity)]
#[test]
Expand Down
File renamed without changes.
15 changes: 7 additions & 8 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ use std::{
};

// Internal
use crate::{
build::Arg,
output::fmt::Colorizer,
output::fmt::Stream,
parse::features::suggestions,
util::{color::ColorChoice, safe_exit, SUCCESS_CODE, USAGE_CODE},
AppSettings, Command,
};
use crate::output::fmt::Colorizer;
use crate::output::fmt::Stream;
use crate::parser::features::suggestions;
use crate::util::{color::ColorChoice, safe_exit, SUCCESS_CODE, USAGE_CODE};
use crate::AppSettings;
use crate::Arg;
use crate::Command;

mod context;
mod kind;
Expand Down
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
#[cfg(not(feature = "std"))]
compile_error!("`std` feature is currently required to build `clap`");

pub use crate::build::Command;
pub use crate::build::{
AppFlags, AppSettings, Arg, ArgFlags, ArgGroup, ArgSettings, PossibleValue, ValueHint,
};
pub use crate::builder::Command;
pub use crate::builder::{Arg, ArgGroup};
pub use crate::error::Error;
pub use crate::parse::{ArgMatches, Indices, OsValues, ValueSource, Values};
pub use crate::parser::ArgMatches;
#[cfg(feature = "color")]
pub use crate::util::color::ColorChoice;
#[cfg(not(feature = "color"))]
Expand All @@ -40,10 +38,11 @@ pub(crate) use crate::util::color::ColorChoice;

pub use crate::derive::{ArgEnum, Args, CommandFactory, FromArgMatches, Parser, Subcommand};

pub use crate::error::{ErrorKind, Result};

#[allow(deprecated)]
pub use crate::build::App;
pub use crate::builder::App;
pub use crate::builder::{AppFlags, AppSettings, ArgFlags, ArgSettings, PossibleValue, ValueHint};
pub use crate::error::{ErrorKind, Result};
pub use crate::parser::{Indices, OsValues, ValueSource, Values};

#[cfg(feature = "yaml")]
#[doc(hidden)]
Expand Down Expand Up @@ -77,14 +76,14 @@ mod macros;
mod derive;

#[cfg(feature = "regex")]
pub use crate::build::RegexRef;
pub use crate::builder::RegexRef;

pub mod builder;
pub mod error;
pub mod parser;

mod build;
mod mkeymap;
mod output;
mod parse;
mod util;

const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a bug \
Expand Down
8 changes: 6 additions & 2 deletions src/mkeymap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::{build::Arg, util::Id, INTERNAL_ERROR_MSG};
use std::iter::Iterator;
use std::ops::Index;
use std::{ffi::OsStr, ffi::OsString};

use std::{ffi::OsStr, ffi::OsString, iter::Iterator, ops::Index};
use crate::util::Id;
use crate::Arg;
use crate::INTERNAL_ERROR_MSG;

#[derive(PartialEq, Eq, Debug, Clone)]
pub(crate) struct Key {
Expand Down
20 changes: 8 additions & 12 deletions src/output/help.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// Std
use std::{
borrow::Cow,
cmp,
fmt::Write as _,
io::{self, Write},
usize,
};
use std::borrow::Cow;
use std::cmp;
use std::fmt::Write as _;
use std::io::{self, Write};
use std::usize;

// Internal
use crate::{
build::{display_arg_val, Arg, Command},
output::{fmt::Colorizer, Usage},
PossibleValue,
};
use crate::builder::{display_arg_val, Arg, Command};
use crate::output::{fmt::Colorizer, Usage};
use crate::PossibleValue;

// Third party
use indexmap::IndexSet;
Expand Down
6 changes: 3 additions & 3 deletions src/output/usage.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use indexmap::IndexSet;

// Internal
use crate::build::AppSettings as AS;
use crate::build::{Arg, ArgPredicate, Command};
use crate::parse::ArgMatcher;
use crate::builder::AppSettings as AS;
use crate::builder::{Arg, ArgPredicate, Command};
use crate::parser::ArgMatcher;
use crate::util::ChildGraph;
use crate::util::Id;
use crate::INTERNAL_ERROR_MSG;
Expand Down
13 changes: 7 additions & 6 deletions src/parse/arg_matcher.rs → src/parser/arg_matcher.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Std
use std::{collections::HashMap, ffi::OsString, mem, ops::Deref};
use std::collections::HashMap;
use std::ffi::OsString;
use std::mem;
use std::ops::Deref;

// Internal
use crate::{
build::{Arg, ArgPredicate, Command},
parse::{ArgMatches, MatchedArg, SubCommand, ValueSource},
util::Id,
};
use crate::builder::{Arg, ArgPredicate, Command};
use crate::parser::{ArgMatches, MatchedArg, SubCommand, ValueSource};
use crate::util::Id;

// Third party
use indexmap::map::Entry;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::cmp::Ordering;

// Internal
use crate::build::Command;
use crate::builder::Command;

/// Produces multiple strings from a given list of possible values which are similar
/// to the passed in value `v` within a certain confidence by least confidence.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// Std
use std::{
borrow::Cow,
ffi::{OsStr, OsString},
fmt::{Debug, Display},
iter::{Cloned, Flatten, Map},
slice::Iter,
str::FromStr,
};
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::fmt::{Debug, Display};
use std::iter::{Cloned, Flatten, Map};
use std::slice::Iter;
use std::str::FromStr;

// Third Party
use indexmap::IndexMap;

// Internal
use crate::parse::MatchedArg;
use crate::parse::ValueSource;
use crate::parser::MatchedArg;
use crate::parser::ValueSource;
use crate::util::{Id, Key};
use crate::{Error, INVALID_UTF8};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{
slice::Iter,
};

use crate::build::ArgPredicate;
use crate::parse::ValueSource;
use crate::builder::ArgPredicate;
use crate::parser::ValueSource;
use crate::util::eq_ignore_case;
use crate::INTERNAL_ERROR_MSG;

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions src/parse/mod.rs → src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! [`Command`][crate::Command] line argument parser

mod arg_matcher;
mod matches;
#[allow(clippy::module_inception)]
mod parser;
mod validator;

pub mod features;
pub mod matches;
pub(crate) mod features;

pub(crate) use self::arg_matcher::ArgMatcher;
pub(crate) use self::matches::{MatchedArg, SubCommand};
Expand Down
14 changes: 7 additions & 7 deletions src/parse/parser.rs → src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use std::{
use clap_lex::RawOsStr;

// Internal
use crate::build::AppSettings as AS;
use crate::build::{Arg, Command};
use crate::builder::AppSettings as AS;
use crate::builder::{Arg, Command};
use crate::error::Error as ClapError;
use crate::error::Result as ClapResult;
use crate::mkeymap::KeyType;
use crate::output::fmt::Stream;
use crate::output::{fmt::Colorizer, Usage};
use crate::parse::features::suggestions;
use crate::parse::{ArgMatcher, SubCommand};
use crate::parse::{Validator, ValueSource};
use crate::parser::features::suggestions;
use crate::parser::{ArgMatcher, SubCommand};
use crate::parser::{Validator, ValueSource};
use crate::util::Id;
use crate::{INTERNAL_ERROR_MSG, INVALID_UTF8};

Expand Down Expand Up @@ -1255,10 +1255,10 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
for (id, val, default) in arg.default_vals_ifs.iter() {
let add = if let Some(a) = matcher.get(id) {
match val {
crate::build::ArgPredicate::Equals(v) => {
crate::builder::ArgPredicate::Equals(v) => {
a.vals_flatten().any(|value| v == value)
}
crate::build::ArgPredicate::IsPresent => true,
crate::builder::ArgPredicate::IsPresent => true,
}
} else {
false
Expand Down
4 changes: 2 additions & 2 deletions src/parse/validator.rs → src/parser/validator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Internal
use crate::build::{AppSettings, Arg, ArgPredicate, Command, PossibleValue};
use crate::builder::{AppSettings, Arg, ArgPredicate, Command, PossibleValue};
use crate::error::{Error, Result as ClapResult};
use crate::output::fmt::Stream;
use crate::output::Usage;
use crate::parse::{ArgMatcher, MatchedArg, ParseState};
use crate::parser::{ArgMatcher, MatchedArg, ParseState};
use crate::util::ChildGraph;
use crate::util::Id;
use crate::{INTERNAL_ERROR_MSG, INVALID_UTF8};
Expand Down
2 changes: 1 addition & 1 deletion tests/derive_ui/next/tuple_struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ error[E0599]: no function or associated item named `parse` found for struct `Opt
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `parse`, perhaps you need to implement it:
candidate #1: `StructOpt`
candidate #1: `Parser`

0 comments on commit 02b4fed

Please sign in to comment.