mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
fix(complete)!: Flatten in prep for stabilization
This commit is contained in:
parent
6727c1537b
commit
de723aaf8a
9 changed files with 32 additions and 25 deletions
|
@ -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:#?}");
|
||||
|
|
|
@ -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") {
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")]
|
||||
|
@ -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")]
|
|
@ -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;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//!
|
||||
//! See [`CompleteEnv`]:
|
||||
//! ```rust
|
||||
//! # use clap_complete::dynamic::CompleteEnv;
|
||||
//! # use clap_complete::CompleteEnv;
|
||||
//! fn cli() -> clap::Command {
|
||||
//! // ...
|
||||
//! # clap::Command::new("empty")
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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)]
|
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue