Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clap): Publicly expose Command::build #3642

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion clap_complete/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ where
G: Generator,
S: Into<String>,
{
cmd._build_all();
cmd.build();

gen.generate(cmd, buf)
}
4 changes: 2 additions & 2 deletions clap_complete/src/generator/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ mod tests {
fn built() -> Command<'static> {
let mut cmd = common_app();

cmd._build_all();
cmd.build();
cmd
}

fn built_with_version() -> Command<'static> {
let mut cmd = common_app().version("3.0");

cmd._build_all();
cmd.build();
cmd
}

Expand Down
2 changes: 1 addition & 1 deletion clap_mangen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Man<'a> {
impl<'a> Man<'a> {
/// Create a new manual page.
pub fn new(mut cmd: clap::Command<'a>) -> Self {
cmd._build_all();
cmd.build();
let title = cmd.get_name().to_owned();
let section = "1".to_owned();
let date = "".to_owned();
Expand Down
16 changes: 14 additions & 2 deletions src/build/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3984,9 +3984,17 @@ impl<'help> App<'help> {
Ok(matcher.into_inner())
}

// used in clap_complete (https://github.com/clap-rs/clap_complete)
#[doc(hidden)]
#[deprecated(since = "3.1.10", note = "Replaced with `Command::build`")]
pub fn _build_all(&mut self) {
self.build();
}

/// Prepare for introspecting on all included [`Command`]s
///
/// Call this on the top-level [`Command`] when done building and before reading state for
/// cases like completions, custom help output, etc.
pub fn build(&mut self) {
self._build();
for subcmd in self.get_subcommands_mut() {
subcmd._build();
Expand Down Expand Up @@ -4047,9 +4055,13 @@ impl<'help> App<'help> {
Some(sc)
}

// used in clap_complete (https://github.com/clap-rs/clap_complete)
#[doc(hidden)]
#[deprecated(since = "3.1.10", note = "Replaced with `Command::build`")]
pub fn _build(&mut self) {
self._build_self()
}

pub(crate) fn _build_self(&mut self) {
debug!("App::_build");
if !self.settings.is_set(AppSettings::Built) {
// Make sure all the globally set flags apply to us as well
Expand Down
2 changes: 1 addition & 1 deletion src/build/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn issue_2090() {
let mut cmd = Command::new("cmd")
.disable_version_flag(true)
.subcommand(Command::new("sub"));
cmd._build();
cmd._build_self();

assert!(cmd
.get_subcommands()
Expand Down
2 changes: 1 addition & 1 deletion src/parse/features/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
None => subcommands
.into_iter()
.filter_map(|subcommand| {
subcommand._build();
subcommand._build_self();

let longs = subcommand.get_keymap().keys().filter_map(|a| {
if let KeyType::Long(v) = a {
Expand Down
2 changes: 1 addition & 1 deletion src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
}
.clone();

sc._build();
sc._build_self();
bin_name.push(' ');
bin_name.push_str(sc.get_name());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/builder/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ fn color_is_global() {
let mut cmd = Command::new("myprog")
.color(clap::ColorChoice::Never)
.subcommand(Command::new("foo"));
cmd._build_all();
cmd.build();
assert_eq!(cmd.get_color(), clap::ColorChoice::Never);

let sub = cmd.get_subcommands().collect::<Vec<_>>()[0];
Expand Down
4 changes: 2 additions & 2 deletions tests/builder/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ fn disable_help_flag_affects_help_subcommand() {
let mut cmd = Command::new("test_app")
.disable_help_flag(true)
.subcommand(Command::new("test").about("Subcommand"));
cmd._build_all();
cmd.build();

let args = cmd
.find_subcommand("help")
Expand Down Expand Up @@ -2918,7 +2918,7 @@ fn help_without_short() {
.arg(arg!(-h --hex <NUM>))
.arg(arg!(--help));

cmd._build_all();
cmd.build();
let help = cmd.get_arguments().find(|a| a.get_id() == "help").unwrap();
assert_eq!(help.get_short(), None);

Expand Down