| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/::type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 5 | |
| 6 | use claprust-analyzer cargo clap 4.6.6 crate/::builderrust-analyzer cargo clap_builder 4.6.6 builder/::ArgExtrust-analyzer cargo clap_builder 4.6.6 builder/arg/ArgExt#; |
| 7 | use claprust-analyzer cargo clap 4.6.6 crate/::builderrust-analyzer cargo clap_builder 4.6.6 builder/::CommandExtrust-analyzer cargo clap_builder 4.6.6 builder/command/CommandExt#; |
| 8 | use clap_lexrust-analyzer cargo clap_lex 1.0.0 crate/::OsStrExtrust-analyzer cargo clap_lex 1.0.0 ext/OsStrExt# as _; |
| 9 | |
| 10 | use superrust-analyzer cargo clap_complete 4.6.8 engine/::CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#; |
| 11 | |
| 12 | /// Extend [`Arg`][clap::Arg] with a completer |
| 13 | /// |
| 14 | /// # Example |
| 15 | /// |
| 16 | /// ```rust |
| 17 | /// use clap::Parser; |
| 18 | /// use clap_complete::engine::{ArgValueCompleter, CompletionCandidate}; |
| 19 | /// |
| 20 | /// fn custom_completer(current: &std::ffi::OsStr) -> Vec<CompletionCandidate> { |
| 21 | /// let mut completions = vec![]; |
| 22 | /// let Some(current) = current.to_str() else { |
| 23 | /// return completions; |
| 24 | /// }; |
| 25 | /// |
| 26 | /// if "foo".starts_with(current) { |
| 27 | /// completions.push(CompletionCandidate::new("foo")); |
| 28 | /// } |
| 29 | /// if "bar".starts_with(current) { |
| 30 | /// completions.push(CompletionCandidate::new("bar")); |
| 31 | /// } |
| 32 | /// if "baz".starts_with(current) { |
| 33 | /// completions.push(CompletionCandidate::new("baz")); |
| 34 | /// } |
| 35 | /// completions |
| 36 | /// } |
| 37 | /// |
| 38 | /// #[derive(Debug, Parser)] |
| 39 | /// struct Cli { |
| 40 | /// #[arg(long, add = ArgValueCompleter::new(custom_completer))] |
| 41 | /// custom: Option<String>, |
| 42 | /// } |
| 43 | /// ``` |
| 44 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 45 | pub struct ArgValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCompleter#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn ValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#>); |
| 46 | |
| 47 | impl ArgValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCompleter# { |
| 48 | /// Create a new `ArgValueCompleter` with a custom completer |
| 49 | pub fn newrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter]new().<C>(completer: C) -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter] |
| 50 | where |
| 51 | C: ValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter# + 'static, |
| 52 | { |
| 53 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(completer)) |
| 54 | } |
| 55 | |
| 56 | /// Candidates that match `current` |
| 57 | /// |
| 58 | /// See [`CompletionCandidate`] for more information. |
| 59 | pub fn completerust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter]complete().(&self, current: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 60 | self.0rust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCompleter#0..completerust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#complete().(current) |
| 61 | } |
| 62 | |
| 63 | /// Candidates that match `current` at `arg_index` within the current occurrence. |
| 64 | /// |
| 65 | /// `arg_index` is the position of the value being completed within an |
| 66 | /// argument's [`num_args`][clap::Arg::num_args] range, starting at `0`. |
| 67 | /// This lets a completer return different candidates for each value of a |
| 68 | /// multi-value argument (for example, a remote name first and a branch |
| 69 | /// name second for `--set-upstream <REMOTE> <BRANCH>`). |
| 70 | /// |
| 71 | /// `arg_index` is unaffected by [`value_delimiter`][clap::Arg::value_delimiter]: |
| 72 | /// it counts shell arguments, not delimiter-separated values. |
| 73 | /// |
| 74 | /// See [`CompletionCandidate`] for more information. |
| 75 | pub fn complete_atrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter]complete_at().(&self, arg_index: usize, current: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 76 | self.0rust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCompleter#0..complete_atrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#complete_at().(arg_index, current) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ArgValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCompleter# { |
| 81 | fn fmtrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 82 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCompleter][Debug]>()) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | impl ArgExtrust-analyzer cargo clap_builder 4.6.6 builder/arg/ArgExt# for ArgValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCompleter# {} |
| 87 | |
| 88 | /// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCompleter`] |
| 89 | /// |
| 90 | /// This is useful when predefined value hints are not enough. |
| 91 | pub trait ValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# { |
| 92 | /// All potential candidates for an argument. |
| 93 | /// |
| 94 | /// See [`CompletionCandidate`] for more information. |
| 95 | fn completerust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#complete().(&self, current: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#>; |
| 96 | |
| 97 | /// All potential candidates for the value at `arg_index` within the current occurrence. |
| 98 | /// |
| 99 | /// `arg_index` is the position of the value being completed within an |
| 100 | /// argument's [`num_args`][clap::Arg::num_args] range, starting at `0`. |
| 101 | /// This lets a completer return different candidates for each value of a |
| 102 | /// multi-value argument (for example, a remote name first and a branch |
| 103 | /// name second for `--set-upstream <REMOTE> <BRANCH>`). |
| 104 | /// |
| 105 | /// `arg_index` is unaffected by [`value_delimiter`][clap::Arg::value_delimiter]: |
| 106 | /// it counts shell arguments, not delimiter-separated values. |
| 107 | /// |
| 108 | /// See [`CompletionCandidate`] for more information. |
| 109 | fn complete_atrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#complete_at().(&self, arg_index: usize, current: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 110 | let _ = arg_index; |
| 111 | self.completerust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter#complete().(current) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | impl<F> ValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter# for F |
| 116 | where |
| 117 | F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, |
| 118 | { |
| 119 | fn completerust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[F][ValueCompleter]complete().(&self, current: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 120 | self(current) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /// Extend [`Arg`][clap::Arg] with a [`ValueCandidates`] |
| 125 | /// |
| 126 | /// # Example |
| 127 | /// |
| 128 | /// ```rust |
| 129 | /// use clap::Parser; |
| 130 | /// use clap_complete::engine::{ArgValueCandidates, CompletionCandidate}; |
| 131 | /// |
| 132 | /// #[derive(Debug, Parser)] |
| 133 | /// struct Cli { |
| 134 | /// #[arg(long, add = ArgValueCandidates::new(|| { vec![ |
| 135 | /// CompletionCandidate::new("foo"), |
| 136 | /// CompletionCandidate::new("bar"), |
| 137 | /// CompletionCandidate::new("baz")] }))] |
| 138 | /// custom: Option<String>, |
| 139 | /// } |
| 140 | /// ``` |
| 141 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 142 | pub struct ArgValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCandidates#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates#>); |
| 143 | |
| 144 | impl ArgValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCandidates# { |
| 145 | /// Create a new `ArgValueCandidates` with a custom completer |
| 146 | pub fn newrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates]new().<C>(completer: C) -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates] |
| 147 | where |
| 148 | C: ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates# + 'static, |
| 149 | { |
| 150 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(completer)) |
| 151 | } |
| 152 | |
| 153 | /// All potential candidates for an argument. |
| 154 | /// |
| 155 | /// See [`CompletionCandidate`] for more information. |
| 156 | pub fn candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates]candidates().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 157 | self.0rust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCandidates#0..candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates#candidates().() |
| 158 | } |
| 159 | |
| 160 | pub(craterust-analyzer cargo clap_complete 4.6.8 crate/) fn value_candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates]value_candidates().(&self) -> &dyn ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates# { |
| 161 | &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Deref]deref().self.0rust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCandidates#0. |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ArgValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCandidates# { |
| 166 | fn fmtrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 167 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[ArgValueCandidates][Debug]>()) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | impl ArgExtrust-analyzer cargo clap_builder 4.6.6 builder/arg/ArgExt# for ArgValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ArgValueCandidates# {} |
| 172 | |
| 173 | /// Extend [`Command`][clap::Command] with a [`ValueCandidates`] |
| 174 | /// |
| 175 | /// # Example |
| 176 | /// ```rust |
| 177 | /// use clap::Parser; |
| 178 | /// use clap_complete::engine::{SubcommandCandidates, CompletionCandidate}; |
| 179 | /// #[derive(Debug, Parser)] |
| 180 | /// #[clap(name = "cli", add = SubcommandCandidates::new(|| { vec![ |
| 181 | /// CompletionCandidate::new("foo"), |
| 182 | /// CompletionCandidate::new("bar"), |
| 183 | /// CompletionCandidate::new("baz")] }))] |
| 184 | /// struct Cli { |
| 185 | /// #[arg(long)] |
| 186 | /// input: Option<String>, |
| 187 | /// } |
| 188 | /// ``` |
| 189 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 190 | pub struct SubcommandCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/SubcommandCandidates#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates#>); |
| 191 | |
| 192 | impl SubcommandCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/SubcommandCandidates# { |
| 193 | /// Create a new `SubcommandCandidates` with a custom completer |
| 194 | pub fn newrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates]new().<C>(completer: C) -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates] |
| 195 | where |
| 196 | C: ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates# + 'static, |
| 197 | { |
| 198 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(completer)) |
| 199 | } |
| 200 | |
| 201 | /// All potential candidates for an external subcommand. |
| 202 | /// |
| 203 | /// See [`CompletionCandidate`] for more information. |
| 204 | pub fn candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates]candidates().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 205 | self.0rust-analyzer cargo clap_complete 4.6.8 engine/custom/SubcommandCandidates#0..candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates#candidates().() |
| 206 | } |
| 207 | |
| 208 | pub(craterust-analyzer cargo clap_complete 4.6.8 crate/) fn value_candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates]value_candidates().(&self) -> &dyn ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates# { |
| 209 | &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Deref]deref().self.0rust-analyzer cargo clap_complete 4.6.8 engine/custom/SubcommandCandidates#0. |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for SubcommandCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/SubcommandCandidates# { |
| 214 | fn fmtrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 215 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[SubcommandCandidates][Debug]>()) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | impl CommandExtrust-analyzer cargo clap_builder 4.6.6 builder/command/CommandExt# for SubcommandCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/SubcommandCandidates# {} |
| 220 | |
| 221 | /// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCandidates`] |
| 222 | /// |
| 223 | /// User-provided completion candidates for an [`Subcommand`][clap::Subcommand], see [`SubcommandCandidates`] |
| 224 | /// |
| 225 | /// This is useful when predefined value hints are not enough. |
| 226 | pub trait ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# { |
| 227 | /// All potential candidates for an argument. |
| 228 | /// |
| 229 | /// See [`CompletionCandidate`] for more information. |
| 230 | fn candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates#candidates().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#>; |
| 231 | } |
| 232 | |
| 233 | impl<F> ValueCandidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCandidates# for F |
| 234 | where |
| 235 | F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#() -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, |
| 236 | { |
| 237 | fn candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[F][ValueCandidates]candidates().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 238 | self() |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /// Complete a value as a [`std::path::Path`] |
| 243 | /// |
| 244 | /// # Example |
| 245 | /// |
| 246 | /// ```rust |
| 247 | /// use clap::Parser; |
| 248 | /// use clap_complete::engine::{ArgValueCompleter, PathCompleter}; |
| 249 | /// |
| 250 | /// #[derive(Debug, Parser)] |
| 251 | /// struct Cli { |
| 252 | /// #[arg(long, add = ArgValueCompleter::new(PathCompleter::file()))] |
| 253 | /// custom: Option<String>, |
| 254 | /// } |
| 255 | /// ``` |
| 256 | pub struct PathCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter# { |
| 257 | current_dirrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#current_dir.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, |
| 258 | #[allow(clippy::type_complexity)] |
| 259 | filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#filter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> bool + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>>, |
| 260 | stdiorust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#stdio.: bool, |
| 261 | } |
| 262 | |
| 263 | impl PathCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter# { |
| 264 | /// Any path is allowed |
| 265 | pub fn anyrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]any().() -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 266 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 267 | filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#filter.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 268 | current_dirrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#current_dir.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 269 | stdiorust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#stdio.: false, |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /// Complete only files |
| 274 | pub fn filerust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]file().() -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 275 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]::anyrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]any().().filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]filter().(|p| p.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_file().()) |
| 276 | } |
| 277 | |
| 278 | /// Complete only directories |
| 279 | pub fn dirrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]dir().() -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 280 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]::anyrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]any().().filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]filter().(|p| p.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().()) |
| 281 | } |
| 282 | |
| 283 | /// Include stdio (`-`) |
| 284 | pub fn stdiorust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]stdio().(mut self) -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 285 | self.stdiorust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#stdio. = true; |
| 286 | self |
| 287 | } |
| 288 | |
| 289 | /// Select which paths should be completed |
| 290 | pub fn filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]filter().( |
| 291 | mut self, |
| 292 | filter: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> bool + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static, |
| 293 | ) -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 294 | self.filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#filter. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(filter)); |
| 295 | self |
| 296 | } |
| 297 | |
| 298 | /// Override [`std::env::current_dir`] |
| 299 | pub fn current_dirrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]current_dir().(mut self, path: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>) -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter] { |
| 300 | self.current_dirrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#current_dir. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()); |
| 301 | self |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for PathCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter# { |
| 306 | fn defaultrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter][Default]default().() -> Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter][Default] { |
| 307 | Selfrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter][Default]::anyrust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter]any().() |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | impl ValueCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/ValueCompleter# for PathCompleterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter# { |
| 312 | fn completerust-analyzer cargo clap_complete 4.6.8 engine/custom/impl#[PathCompleter][ValueCompleter]complete().(&self, current: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 313 | let filter = self.filterrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#filter..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&|_| true); |
| 314 | let mut current_dir_actual = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 315 | let current_dir = self.current_dirrust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#current_dir..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| { |
| 316 | current_dir_actual = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/current_dir().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(); |
| 317 | current_dir_actual.as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() |
| 318 | }); |
| 319 | let mut candidates = complete_pathrust-analyzer cargo clap_complete 4.6.8 engine/custom/complete_path().(current, current_dir, filter); |
| 320 | if self.stdiorust-analyzer cargo clap_complete 4.6.8 engine/custom/PathCompleter#stdio. && current.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]is_empty().() { |
| 321 | candidates.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#::newrust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]new().("-").helprust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]help().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("stdio".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))); |
| 322 | } |
| 323 | candidates |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | pub(craterust-analyzer cargo clap_complete 4.6.8 crate/) fn complete_pathrust-analyzer cargo clap_complete 4.6.8 engine/custom/complete_path().( |
| 328 | value_os: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, |
| 329 | current_dir: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, |
| 330 | is_wanted: &dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> bool, |
| 331 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 332 | let mut completions = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 333 | let mut potential = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 334 | |
| 335 | let value_path = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(value_os); |
| 336 | let (prefix, current) = split_file_namerust-analyzer cargo clap_complete 4.6.8 engine/custom/split_file_name().(value_path); |
| 337 | let current = current.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().(); |
| 338 | let search_root = if prefix.is_absoluterust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_absolute().() { |
| 339 | prefix.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().() |
| 340 | } else if prefix.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]iter().().nextrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[`Iter<'a>`][Iterator]next().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("~")) { |
| 341 | let prefix = prefix.strip_prefixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]strip_prefix().("~").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(prefix); |
| 342 | let home_dir = match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::home_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/home_dir().() { |
| 343 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(home_dir) => home_dir, |
| 344 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 345 | // Can't complete without a `home_dir` |
| 346 | return completions; |
| 347 | } |
| 348 | }; |
| 349 | home_dir.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(prefix) |
| 350 | } else { |
| 351 | let current_dir = match current_dir { |
| 352 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(current_dir) => current_dir, |
| 353 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 354 | // Can't complete without a `current_dir` |
| 355 | return completions; |
| 356 | } |
| 357 | }; |
| 358 | current_dir.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(prefix) |
| 359 | }; |
| 360 | debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("complete_path: search_root={search_root:?}, prefix={prefix:?}"); |
| 361 | |
| 362 | if value_os.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]is_empty().() && is_wanted(&search_root) { |
| 363 | completions.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(".".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 364 | } |
| 365 | |
| 366 | for entry in stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(&search_root) |
| 367 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 368 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][IntoIterator]into_iter().() |
| 369 | .flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() |
| 370 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#::okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().) |
| 371 | { |
| 372 | let raw_file_name = entry.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().(); |
| 373 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().raw_file_name.starts_withrust-analyzer cargo clap_lex 1.0.0 ext/impl#[OsStr][OsStrExt]starts_with().(¤t) { |
| 374 | continue; |
| 375 | } |
| 376 | |
| 377 | if entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().().is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().() { |
| 378 | let mut suggestion = prefix.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&raw_file_name); |
| 379 | suggestion.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]push().(""); // Ensure trailing `/` |
| 380 | let candidate = CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#::newrust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]new().(suggestion.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]as_os_str().().to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr][ToOwned]to_owned().()) |
| 381 | .hiderust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]hide().(is_hiddenrust-analyzer cargo clap_complete 4.6.8 engine/custom/is_hidden().(&raw_file_name)); |
| 382 | |
| 383 | if is_wanted(&entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().()) { |
| 384 | completions.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(candidate); |
| 385 | } else { |
| 386 | potential.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(candidate); |
| 387 | } |
| 388 | } else { |
| 389 | if is_wanted(&entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().()) { |
| 390 | let suggestion = prefix.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&raw_file_name); |
| 391 | let candidate = CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#::newrust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]new().(suggestion.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]as_os_str().().to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr][ToOwned]to_owned().()) |
| 392 | .hiderust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]hide().(is_hiddenrust-analyzer cargo clap_complete 4.6.8 engine/custom/is_hidden().(&raw_file_name)); |
| 393 | completions.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(candidate); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | completions.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 398 | potential.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 399 | completions.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(potential); |
| 400 | |
| 401 | completions |
| 402 | } |
| 403 | |
| 404 | fn is_hiddenrust-analyzer cargo clap_complete 4.6.8 engine/custom/is_hidden().(file_name: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) -> bool { |
| 405 | file_name.starts_withrust-analyzer cargo clap_lex 1.0.0 ext/impl#[OsStr][OsStrExt]starts_with().(".") |
| 406 | } |
| 407 | |
| 408 | fn split_file_namerust-analyzer cargo clap_complete 4.6.8 engine/custom/split_file_name().(path: &stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> (&stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#) { |
| 409 | // Workaround that `Path::new("name/").file_name()` reports `"name"` |
| 410 | if path_has_namerust-analyzer cargo clap_complete 4.6.8 engine/custom/path_has_name().(path) { |
| 411 | ( |
| 412 | path.parentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]parent().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("")), |
| 413 | path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("not called with `..`"), |
| 414 | ) |
| 415 | } else { |
| 416 | (path, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[`&OsStr`][Default]default().()) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | fn path_has_namerust-analyzer cargo clap_complete 4.6.8 engine/custom/path_has_name().(path: &stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> bool { |
| 421 | let path_bytes = path.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]as_os_str().().as_encoded_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]as_encoded_bytes().(); |
| 422 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(trailing) = path_bytes.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() else { |
| 423 | return false; |
| 424 | }; |
| 425 | let trailing = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().trailing as char; |
| 426 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::is_separatorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/is_separator().(trailing) && path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 427 | } |
| 428 | |
| 429 | /// Create [`CompletionCandidate`]s for [`clap::builder::PossibleValue`] |
| 430 | /// |
| 431 | /// This is implicitly applied for arguments with either a [`clap::builder::PossibleValuesParser`] or [`clap::builder::EnumValueParser`]. |
| 432 | /// |
| 433 | /// Using this explicitly is intended for arguments that also accept other value formats that need |
| 434 | /// to be completed and the completer is eager ([`ValueCandidates`]). |
| 435 | /// For lazy completion, see [`complete_possible_values`]. |
| 436 | pub fn possible_value_candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/possible_value_candidates().( |
| 437 | values: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = claprust-analyzer cargo clap 4.6.6 crate/::builderrust-analyzer cargo clap_builder 4.6.6 builder/::PossibleValuerust-analyzer cargo clap_builder 4.6.6 builder/possible_value/PossibleValue#>, |
| 438 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 439 | values |
| 440 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().() |
| 441 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|p| { |
| 442 | CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#::newrust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]new().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().(p.get_namerust-analyzer cargo clap_builder 4.6.6 builder/possible_value/impl#[PossibleValue]get_name().())) |
| 443 | .helprust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]help().(p.get_helprust-analyzer cargo clap_builder 4.6.6 builder/possible_value/impl#[PossibleValue]get_help().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().()) |
| 444 | .hiderust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]hide().(p.is_hide_setrust-analyzer cargo clap_builder 4.6.6 builder/possible_value/impl#[PossibleValue]is_hide_set().()) |
| 445 | }) |
| 446 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 447 | } |
| 448 | |
| 449 | /// Create [`CompletionCandidate`]s for [`clap::builder::PossibleValue`] |
| 450 | /// |
| 451 | /// This is implicitly applied for arguments with either a [`clap::builder::PossibleValuesParser`] or [`clap::builder::EnumValueParser`]. |
| 452 | /// |
| 453 | /// Using this explicitly is intended for arguments that also accept other value formats that need |
| 454 | /// to be completed and the completer is lazy ([`ValueCompleter`]). |
| 455 | /// For eager completion, see [`possible_value_candidates`]. |
| 456 | pub fn complete_possible_valuesrust-analyzer cargo clap_complete 4.6.8 engine/custom/complete_possible_values().( |
| 457 | value: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, |
| 458 | values: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = claprust-analyzer cargo clap 4.6.6 crate/::builderrust-analyzer cargo clap_builder 4.6.6 builder/::PossibleValuerust-analyzer cargo clap_builder 4.6.6 builder/possible_value/PossibleValue#>, |
| 459 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CompletionCandidaterust-analyzer cargo clap_complete 4.6.8 engine/candidate/CompletionCandidate#> { |
| 460 | let mut values = possible_value_candidatesrust-analyzer cargo clap_complete 4.6.8 engine/custom/possible_value_candidates().(values); |
| 461 | values.retainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]retain().(|comp| comp.get_valuerust-analyzer cargo clap_complete 4.6.8 engine/candidate/impl#[CompletionCandidate]get_value().().starts_withrust-analyzer cargo clap_lex 1.0.0 ext/impl#[OsStr][OsStrExt]starts_with().(&value.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().())); |
| 462 | values |
| 463 | } |