Skip to content

Commit de723aa

Browse files
committed
fix(complete)!: Flatten in prep for stabilization
1 parent 6727c15 commit de723aa

File tree

9 files changed

+32
-25
lines changed

9 files changed

+32
-25
lines changed

clap_complete/examples/dynamic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ fn command() -> clap::Command {
1616
.value_parser(["json", "yaml", "toml"]),
1717
)
1818
.args_conflicts_with_subcommands(true);
19-
clap_complete::dynamic::CompleteCommand::augment_subcommands(cmd)
19+
clap_complete::CompleteCommand::augment_subcommands(cmd)
2020
}
2121

2222
fn main() {
23-
clap_complete::dynamic::CompleteEnv::with_factory(command).complete();
23+
clap_complete::CompleteEnv::with_factory(command).complete();
2424

2525
let cmd = command();
2626
let matches = cmd.get_matches();
27-
if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) {
27+
if let Ok(completions) = clap_complete::CompleteCommand::from_arg_matches(&matches) {
2828
completions.complete(&mut command());
2929
} else {
3030
println!("{matches:#?}");

clap_complete/examples/exhaustive.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap_complete::{generate, Generator, Shell};
55

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

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

1818
#[cfg(feature = "unstable-command")]
19-
if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) {
19+
if let Ok(completions) = clap_complete::CompleteCommand::from_arg_matches(&matches) {
2020
completions.complete(&mut cli());
2121
return;
2222
};
@@ -199,6 +199,6 @@ fn cli() -> clap::Command {
199199
]),
200200
]);
201201
#[cfg(feature = "unstable-command")]
202-
let cli = clap_complete::dynamic::CompleteCommand::augment_subcommands(cli);
202+
let cli = clap_complete::CompleteCommand::augment_subcommands(cli);
203203
cli
204204
}

clap_complete/src/dynamic/command/mod.rs renamed to clap_complete/src/command/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub use shells::*;
5555
/// ```no_run
5656
/// // src/main.rs
5757
/// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};
58-
/// use clap_complete::dynamic::CompleteCommand;
58+
/// use clap_complete::CompleteCommand;
5959
///
6060
/// #[derive(Parser, Debug)]
6161
/// #[clap(name = "dynamic", about = "A dynamic command line tool")]
@@ -122,7 +122,7 @@ impl CompleteCommand {
122122
/// ```no_run
123123
/// // src/main.rs
124124
/// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};
125-
/// use clap_complete::dynamic::CompleteArgs;
125+
/// use clap_complete::CompleteArgs;
126126
///
127127
/// #[derive(Parser, Debug)]
128128
/// #[clap(name = "dynamic", about = "A dynamic command line tool")]

clap_complete/src/dynamic/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@ mod candidate;
99
mod complete;
1010
mod custom;
1111

12-
#[cfg(feature = "unstable-command")]
13-
pub mod command;
14-
pub mod env;
15-
1612
pub use candidate::CompletionCandidate;
1713
pub use complete::complete;
1814
pub use custom::ArgValueCompleter;
1915
pub use custom::CustomCompleter;
20-
21-
#[cfg(feature = "unstable-command")]
22-
pub use command::CompleteArgs;
23-
#[cfg(feature = "unstable-command")]
24-
pub use command::CompleteCommand;
25-
pub use env::CompleteEnv;

clap_complete/src/dynamic/env/mod.rs renamed to clap_complete/src/env/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! See [`CompleteEnv`]:
44
//! ```rust
5-
//! # use clap_complete::dynamic::CompleteEnv;
5+
//! # use clap_complete::CompleteEnv;
66
//! fn cli() -> clap::Command {
77
//! // ...
88
//! # clap::Command::new("empty")
@@ -64,7 +64,7 @@ pub use shells::*;
6464
/// - Flexibility: there is no concern over it interfering with other CLI logic
6565
///
6666
/// ```rust
67-
/// # use clap_complete::dynamic::CompleteEnv;
67+
/// # use clap_complete::CompleteEnv;
6868
/// fn cli() -> clap::Command {
6969
/// // ...
7070
/// # clap::Command::new("empty")
@@ -90,7 +90,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> {
9090
///
9191
/// Builder:
9292
/// ```rust
93-
/// # use clap_complete::dynamic::CompleteEnv;
93+
/// # use clap_complete::CompleteEnv;
9494
/// fn cli() -> clap::Command {
9595
/// // ...
9696
/// # clap::Command::new("empty")
@@ -107,7 +107,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> {
107107
/// Derive:
108108
/// ```
109109
/// # use clap::Parser;
110-
/// # use clap_complete::dynamic::CompleteEnv;
110+
/// # use clap_complete::CompleteEnv;
111111
/// use clap::CommandFactory as _;
112112
///
113113
/// #[derive(Debug, Parser)]

clap_complete/src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,26 @@ const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a
6666
mod macros;
6767

6868
pub mod aot;
69+
#[cfg(feature = "unstable-command")]
70+
pub mod command;
6971
#[cfg(feature = "unstable-dynamic")]
7072
pub mod dynamic;
73+
#[cfg(feature = "unstable-dynamic")]
74+
pub mod env;
75+
76+
pub use clap::ValueHint;
77+
#[cfg(feature = "unstable-command")]
78+
pub use command::CompleteArgs;
79+
#[cfg(feature = "unstable-command")]
80+
pub use command::CompleteCommand;
81+
#[doc(inline)]
82+
#[cfg(feature = "unstable-dynamic")]
83+
pub use dynamic::ArgValueCompleter;
84+
#[doc(inline)]
85+
#[cfg(feature = "unstable-dynamic")]
86+
pub use dynamic::CompletionCandidate;
87+
#[cfg(feature = "unstable-dynamic")]
88+
pub use env::CompleteEnv;
7189

7290
/// Deprecated, see [`aot`]
7391
pub mod generator {
@@ -93,4 +111,3 @@ pub use aot::generate_to;
93111
pub use aot::Generator;
94112
/// Deprecated, see [`aot::Shell`]
95113
pub use aot::Shell;
96-
pub use clap::ValueHint;

clap_complete/tests/testsuite/bash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ fn value_terminator() {
114114
#[cfg(feature = "unstable-command")]
115115
#[test]
116116
fn register_minimal() {
117-
use clap_complete::dynamic::command::CommandCompleter as _;
117+
use clap_complete::command::CommandCompleter as _;
118118

119119
let name = "my-app";
120120
let bin = name;
121121
let completer = name;
122122

123123
let mut buf = Vec::new();
124-
clap_complete::dynamic::command::Bash
124+
clap_complete::command::Bash
125125
.write_registration(name, bin, completer, &mut buf)
126126
.unwrap();
127127
snapbox::Assert::new()

0 commit comments

Comments
 (0)