Skip to content

Commit

Permalink
fix(complete)!: Flatten in prep for stabilization
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 16, 2024
1 parent 6727c15 commit de723aa
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
6 changes: 3 additions & 3 deletions clap_complete/examples/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fn command() -> clap::Command {
.value_parser(["json", "yaml", "toml"]),
)
.args_conflicts_with_subcommands(true);
clap_complete::dynamic::CompleteCommand::augment_subcommands(cmd)
clap_complete::CompleteCommand::augment_subcommands(cmd)
}

fn main() {
clap_complete::dynamic::CompleteEnv::with_factory(command).complete();
clap_complete::CompleteEnv::with_factory(command).complete();

let cmd = command();
let matches = cmd.get_matches();
if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) {
if let Ok(completions) = clap_complete::CompleteCommand::from_arg_matches(&matches) {
completions.complete(&mut command());
} else {
println!("{matches:#?}");
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/examples/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap_complete::{generate, Generator, Shell};

fn main() {
#[cfg(feature = "unstable-dynamic")]
clap_complete::dynamic::CompleteEnv::with_factory(cli).complete();
clap_complete::CompleteEnv::with_factory(cli).complete();

let matches = cli().get_matches();
if let Some(generator) = matches.get_one::<Shell>("generate") {
Expand All @@ -16,7 +16,7 @@ fn main() {
}

#[cfg(feature = "unstable-command")]
if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) {
if let Ok(completions) = clap_complete::CompleteCommand::from_arg_matches(&matches) {
completions.complete(&mut cli());
return;
};
Expand Down Expand Up @@ -199,6 +199,6 @@ fn cli() -> clap::Command {
]),
]);
#[cfg(feature = "unstable-command")]
let cli = clap_complete::dynamic::CompleteCommand::augment_subcommands(cli);
let cli = clap_complete::CompleteCommand::augment_subcommands(cli);
cli
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub use shells::*;
/// ```no_run
/// // src/main.rs
/// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};
/// use clap_complete::dynamic::CompleteCommand;
/// use clap_complete::CompleteCommand;
///
/// #[derive(Parser, Debug)]
/// #[clap(name = "dynamic", about = "A dynamic command line tool")]
Expand Down Expand Up @@ -122,7 +122,7 @@ impl CompleteCommand {
/// ```no_run
/// // src/main.rs
/// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};
/// use clap_complete::dynamic::CompleteArgs;
/// use clap_complete::CompleteArgs;
///
/// #[derive(Parser, Debug)]
/// #[clap(name = "dynamic", about = "A dynamic command line tool")]
Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions clap_complete/src/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ mod candidate;
mod complete;
mod custom;

#[cfg(feature = "unstable-command")]
pub mod command;
pub mod env;

pub use candidate::CompletionCandidate;
pub use complete::complete;
pub use custom::ArgValueCompleter;
pub use custom::CustomCompleter;

#[cfg(feature = "unstable-command")]
pub use command::CompleteArgs;
#[cfg(feature = "unstable-command")]
pub use command::CompleteCommand;
pub use env::CompleteEnv;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! See [`CompleteEnv`]:
//! ```rust
//! # use clap_complete::dynamic::CompleteEnv;
//! # use clap_complete::CompleteEnv;
//! fn cli() -> clap::Command {
//! // ...
//! # clap::Command::new("empty")
Expand Down Expand Up @@ -64,7 +64,7 @@ pub use shells::*;
/// - Flexibility: there is no concern over it interfering with other CLI logic
///
/// ```rust
/// # use clap_complete::dynamic::CompleteEnv;
/// # use clap_complete::CompleteEnv;
/// fn cli() -> clap::Command {
/// // ...
/// # clap::Command::new("empty")
Expand All @@ -90,7 +90,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> {
///
/// Builder:
/// ```rust
/// # use clap_complete::dynamic::CompleteEnv;
/// # use clap_complete::CompleteEnv;
/// fn cli() -> clap::Command {
/// // ...
/// # clap::Command::new("empty")
Expand All @@ -107,7 +107,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> {
/// Derive:
/// ```
/// # use clap::Parser;
/// # use clap_complete::dynamic::CompleteEnv;
/// # use clap_complete::CompleteEnv;
/// use clap::CommandFactory as _;
///
/// #[derive(Debug, Parser)]
Expand Down
File renamed without changes.
19 changes: 18 additions & 1 deletion clap_complete/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,26 @@ const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a
mod macros;

pub mod aot;
#[cfg(feature = "unstable-command")]
pub mod command;
#[cfg(feature = "unstable-dynamic")]
pub mod dynamic;
#[cfg(feature = "unstable-dynamic")]
pub mod env;

pub use clap::ValueHint;
#[cfg(feature = "unstable-command")]
pub use command::CompleteArgs;
#[cfg(feature = "unstable-command")]
pub use command::CompleteCommand;
#[doc(inline)]
#[cfg(feature = "unstable-dynamic")]
pub use dynamic::ArgValueCompleter;
#[doc(inline)]
#[cfg(feature = "unstable-dynamic")]
pub use dynamic::CompletionCandidate;
#[cfg(feature = "unstable-dynamic")]
pub use env::CompleteEnv;

/// Deprecated, see [`aot`]
pub mod generator {
Expand All @@ -93,4 +111,3 @@ pub use aot::generate_to;
pub use aot::Generator;
/// Deprecated, see [`aot::Shell`]
pub use aot::Shell;
pub use clap::ValueHint;
4 changes: 2 additions & 2 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ fn value_terminator() {
#[cfg(feature = "unstable-command")]
#[test]
fn register_minimal() {
use clap_complete::dynamic::command::CommandCompleter as _;
use clap_complete::command::CommandCompleter as _;

let name = "my-app";
let bin = name;
let completer = name;

let mut buf = Vec::new();
clap_complete::dynamic::command::Bash
clap_complete::command::Bash
.write_registration(name, bin, completer, &mut buf)
.unwrap();
snapbox::Assert::new()
Expand Down

0 comments on commit de723aa

Please sign in to comment.