| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# as _, |
| 3 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}, |
| 4 | }; |
| 5 | |
| 6 | use claprust-analyzer cargo clap 4.6.6 crate/::{Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#, Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#}; |
| 7 | |
| 8 | use craterust-analyzer cargo clap_complete 4.6.8 crate/::generatorrust-analyzer cargo clap_complete 4.6.8 generator/::{Generatorrust-analyzer cargo clap_complete 4.6.8 aot/generator/Generator#, utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/}; |
| 9 | |
| 10 | /// Generate bash completion file |
| 11 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 12 | pub struct Bashrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/Bash#; |
| 13 | |
| 14 | impl Generatorrust-analyzer cargo clap_complete 4.6.8 aot/generator/Generator# for Bashrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/Bash# { |
| 15 | fn file_namerust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/impl#[Bash][Generator]file_name().(&self, name: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 16 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{name}.bash") |
| 17 | } |
| 18 | |
| 19 | fn generaterust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/impl#[Bash][Generator]generate().(&self, cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, buf: &mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) { |
| 20 | self.try_generaterust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/impl#[Bash][Generator]try_generate().(cmd, buf) |
| 21 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to write completion file"); |
| 22 | } |
| 23 | |
| 24 | fn try_generaterust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/impl#[Bash][Generator]try_generate().(&self, cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, buf: &mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 25 | let bin_name = cmd |
| 26 | .get_bin_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_bin_name().() |
| 27 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("crate::generate should have set the bin_name"); |
| 28 | |
| 29 | let fn_name = bin_name.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('-', "__"); |
| 30 | |
| 31 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 32 | buf, |
| 33 | "_{name}() {{ |
| 34 | local i cur prev opts cmd |
| 35 | COMPREPLY=() |
| 36 | if [[ \"${{BASH_VERSINFO[0]}}\" -ge 4 ]]; then |
| 37 | cur=\"$2\" |
| 38 | else |
| 39 | cur=\"${{COMP_WORDS[COMP_CWORD]}}\" |
| 40 | fi |
| 41 | prev=\"$3\" |
| 42 | cmd=\"\" |
| 43 | opts=\"\" |
| 44 | |
| 45 | for i in \"${{COMP_WORDS[@]:0:COMP_CWORD}}\" |
| 46 | do |
| 47 | case \"${{cmd}},${{i}}\" in |
| 48 | \",$1\") |
| 49 | cmd=\"{cmd}\" |
| 50 | ;;{subcmds} |
| 51 | *) |
| 52 | ;; |
| 53 | esac |
| 54 | done |
| 55 | |
| 56 | case \"${{cmd}}\" in |
| 57 | {cmd}) |
| 58 | opts=\"{name_opts}\" |
| 59 | if [[ ${{cur}} == -* || ${{COMP_CWORD}} -eq 1 ]] ; then |
| 60 | COMPREPLY=( $(compgen -W \"${{opts}}\" -- \"${{cur}}\") ) |
| 61 | return 0 |
| 62 | fi |
| 63 | case \"${{prev}}\" in{name_opts_details} |
| 64 | *) |
| 65 | COMPREPLY=() |
| 66 | ;; |
| 67 | esac |
| 68 | COMPREPLY=( $(compgen -W \"${{opts}}\" -- \"${{cur}}\") ) |
| 69 | return 0 |
| 70 | ;;{subcmd_details} |
| 71 | esac |
| 72 | }} |
| 73 | |
| 74 | if [[ \"${{BASH_VERSINFO[0]}}\" -eq 4 && \"${{BASH_VERSINFO[1]}}\" -ge 4 || \"${{BASH_VERSINFO[0]}}\" -gt 4 ]]; then |
| 75 | complete -F _{name} -o nosort -o bashdefault -o default {name} |
| 76 | else |
| 77 | complete -F _{name} -o bashdefault -o default {name} |
| 78 | fi |
| 79 | ", |
| 80 | name = bin_name, |
| 81 | cmd = fn_name, |
| 82 | name_opts = all_options_for_pathrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/all_options_for_path().(cmd, bin_name), |
| 83 | name_opts_details = option_details_for_pathrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/option_details_for_path().(cmd, bin_name), |
| 84 | subcmds = all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/all_subcommands().(cmd, &fn_name), |
| 85 | subcmd_details = subcommand_detailsrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/subcommand_details().(cmd) |
| 86 | ) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | fn all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/all_subcommands().(cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, parent_fn_name: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 91 | debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("all_subcommands"); |
| 92 | |
| 93 | fn add_commandrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/add_command().( |
| 94 | parent_fn_name: &str, |
| 95 | cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, |
| 96 | subcmds: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)>, |
| 97 | ) { |
| 98 | let fn_name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 99 | "{parent_fn_name}{CMD_SEP}{cmd_name}", |
| 100 | parent_fn_name = parent_fn_name, |
| 101 | cmd_name = cmd.get_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_name().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().().replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('-', CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.) |
| 102 | ); |
| 103 | subcmds.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(( |
| 104 | parent_fn_name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 105 | cmd.get_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_name().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 106 | fn_name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 107 | )); |
| 108 | for alias in cmd.get_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_visible_aliases().() { |
| 109 | subcmds.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((parent_fn_name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), alias.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), fn_name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())); |
| 110 | } |
| 111 | for subcmd in cmd.get_subcommandsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_subcommands().() { |
| 112 | add_commandrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/add_command().(&fn_name, subcmd, subcmds); |
| 113 | } |
| 114 | } |
| 115 | let mut subcmds = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 116 | for subcmd in cmd.get_subcommandsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_subcommands().() { |
| 117 | add_commandrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/add_command().(parent_fn_name, subcmd, &mut subcmds); |
| 118 | } |
| 119 | subcmds.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 120 | |
| 121 | let mut cases = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()]; |
| 122 | for (parent_fn_name, name, fn_name) in subcmds { |
| 123 | cases.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 124 | "{parent_fn_name},{name}) |
| 125 | cmd=\"{fn_name}\" |
| 126 | ;;", |
| 127 | )); |
| 128 | } |
| 129 | |
| 130 | cases.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n ") |
| 131 | } |
| 132 | |
| 133 | fn subcommand_detailsrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/subcommand_details().(cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 134 | debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("subcommand_details"); |
| 135 | |
| 136 | let mut subcmd_dets = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()]; |
| 137 | let mut scs = utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/all_subcommands().(cmd) |
| 138 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 139 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.1.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(' ', CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.)) |
| 140 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 141 | |
| 142 | scs.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 143 | scs.deduprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]dedup().(); |
| 144 | |
| 145 | subcmd_dets.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(scs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|sc| { |
| 146 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 147 | "{subcmd}) |
| 148 | opts=\"{sc_opts}\" |
| 149 | if [[ ${{cur}} == -* || ${{COMP_CWORD}} -eq {level} ]] ; then |
| 150 | COMPREPLY=( $(compgen -W \"${{opts}}\" -- \"${{cur}}\") ) |
| 151 | return 0 |
| 152 | fi |
| 153 | case \"${{prev}}\" in{opts_details} |
| 154 | *) |
| 155 | COMPREPLY=() |
| 156 | ;; |
| 157 | esac |
| 158 | COMPREPLY=( $(compgen -W \"${{opts}}\" -- \"${{cur}}\") ) |
| 159 | return 0 |
| 160 | ;;", |
| 161 | subcmd = sc.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('-', CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.), |
| 162 | sc_opts = all_options_for_pathrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/all_options_for_path().(cmd, sc), |
| 163 | level = sc.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| 1).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().::<u64>(), |
| 164 | opts_details = option_details_for_pathrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/option_details_for_path().(cmd, sc) |
| 165 | ) |
| 166 | })); |
| 167 | |
| 168 | subcmd_dets.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n ") |
| 169 | } |
| 170 | |
| 171 | fn option_details_for_pathrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/option_details_for_path().(cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, path: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 172 | debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("option_details_for_path: path={path}"); |
| 173 | |
| 174 | let p = utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(cmd, path.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.).skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()); |
| 175 | let mut opts = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()]; |
| 176 | |
| 177 | for o in p.get_optsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_opts().() { |
| 178 | let compopt = match o.get_value_hintrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_value_hint().() { |
| 179 | ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::FilePathrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#FilePath# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("compopt -o filenames"), |
| 180 | ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::DirPathrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#DirPath# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("compopt -o plusdirs"), |
| 181 | ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::Otherrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#Other# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("compopt -o nospace"), |
| 182 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 183 | }; |
| 184 | |
| 185 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(longs) = o.get_long_and_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long_and_visible_aliases().() { |
| 186 | opts.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(longs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|long| { |
| 187 | let mut v = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("--{})", long)]; |
| 188 | |
| 189 | if o.get_value_hintrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_value_hint().() rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().==rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq(). rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::FilePathrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#FilePath# { |
| 190 | v.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().([ |
| 191 | "local oldifs".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 192 | r#"if [ -n "${IFS+x}" ]; then"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 193 | r#" oldifs="$IFS""#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 194 | "fi".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 195 | r#"IFS=$'\n'"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 196 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("COMPREPLY=({})", vals_forrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/vals_for().(o)), |
| 197 | r#"if [ -n "${oldifs+x}" ]; then"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 198 | r#" IFS="$oldifs""#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 199 | "fi".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 200 | ]); |
| 201 | } else { |
| 202 | v.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("COMPREPLY=({})", vals_forrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/vals_for().(o))); |
| 203 | } |
| 204 | |
| 205 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(copt) = compopt { |
| 206 | v.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().([ |
| 207 | r#"if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 208 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" {copt}"), |
| 209 | "fi".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 210 | ]); |
| 211 | } |
| 212 | |
| 213 | v.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(["return 0", ";;"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().s).to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())); |
| 214 | v.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n ") |
| 215 | })); |
| 216 | } |
| 217 | |
| 218 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(shorts) = o.get_short_and_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_short_and_visible_aliases().() { |
| 219 | opts.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(shorts.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|short| { |
| 220 | let mut v = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-{})", short)]; |
| 221 | |
| 222 | if o.get_value_hintrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_value_hint().() rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().==rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq(). rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::FilePathrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#FilePath# { |
| 223 | v.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().([ |
| 224 | "local oldifs".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 225 | r#"if [ -n "${IFS+x}" ]; then"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 226 | r#" oldifs="$IFS""#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 227 | "fi".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 228 | r#"IFS=$'\n'"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 229 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("COMPREPLY=({})", vals_forrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/vals_for().(o)), |
| 230 | r#"if [ -n "${oldifs+x}" ]; then"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 231 | r#" IFS="$oldifs""#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 232 | "fi".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 233 | ]); |
| 234 | } else { |
| 235 | v.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("COMPREPLY=({})", vals_forrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/vals_for().(o))); |
| 236 | } |
| 237 | |
| 238 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(copt) = compopt { |
| 239 | v.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().([ |
| 240 | r#"if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then"#.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 241 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" {copt}"), |
| 242 | "fi".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 243 | ]); |
| 244 | } |
| 245 | |
| 246 | v.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(["return 0", ";;"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().s).to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())); |
| 247 | v.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n ") |
| 248 | })); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | opts.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n ") |
| 253 | } |
| 254 | |
| 255 | fn vals_forrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/vals_for().(o: &Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 256 | debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("vals_for: o={}", o.get_id()); |
| 257 | |
| 258 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vals) = utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::possible_valuesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/possible_values().(o) { |
| 259 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 260 | "$(compgen -W \"{}\" -- \"${{cur}}\")", |
| 261 | vals.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 262 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|pv| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pv.is_hide_setrust-analyzer cargo clap_builder 4.6.6 builder/possible_value/impl#[PossibleValue]is_hide_set().()) |
| 263 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|n| n.get_namerust-analyzer cargo clap_builder 4.6.6 builder/possible_value/impl#[PossibleValue]get_name().()) |
| 264 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 265 | .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(" ") |
| 266 | ) |
| 267 | } else if o.get_value_hintrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_value_hint().() rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().==rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq(). rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::DirPathrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#DirPath# { |
| 268 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("") // should be empty to avoid duplicate candidates |
| 269 | } else if o.get_value_hintrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_value_hint().() rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().==rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq(). rust-analyzer cargo clap_builder 4.6.6 builder/value_hint/impl#[ValueHint][`PartialEq<Self>`]eq().ValueHintrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#::Otherrust-analyzer cargo clap_builder 4.6.6 builder/value_hint/ValueHint#Other# { |
| 270 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("\"${cur}\"") |
| 271 | } else { |
| 272 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("$(compgen -f \"${cur}\")") |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | fn all_options_for_pathrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/all_options_for_path().(cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, path: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 277 | debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("all_options_for_path: path={path}"); |
| 278 | |
| 279 | let p = utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(cmd, path.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.).skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()); |
| 280 | |
| 281 | let mut opts = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 282 | for short in utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::shorts_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/shorts_and_visible_aliases().(p) { |
| 283 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut opts, "-{short} ").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("writing to String is infallible"); |
| 284 | } |
| 285 | for long in utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::longs_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/longs_and_visible_aliases().(p) { |
| 286 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut opts, "--{long} ").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("writing to String is infallible"); |
| 287 | } |
| 288 | for pos in p.get_positionalsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_positionals().() { |
| 289 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vals) = utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::possible_valuesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/possible_values().(pos) { |
| 290 | for value in vals { |
| 291 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut opts, "{} ", value.get_namerust-analyzer cargo clap_builder 4.6.6 builder/possible_value/impl#[PossibleValue]get_name().()) |
| 292 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("writing to String is infallible"); |
| 293 | } |
| 294 | } |
| 295 | // A positional without possible values has no literal completion word to |
| 296 | // offer here; emitting its `<NAME>`/`[NAME]` usage placeholder would make |
| 297 | // bash glob-expand the brackets (#6407), so leave it to the `-o default` |
| 298 | // (filename) fallback instead. |
| 299 | } |
| 300 | for (sc, _) in utilsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/subcommands().(p) { |
| 301 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut opts, "{sc} ").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("writing to String is infallible"); |
| 302 | } |
| 303 | opts.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]pop().(); |
| 304 | |
| 305 | opts |
| 306 | } |
| 307 | |
| 308 | const CMD_SEPrust-analyzer cargo clap_complete 4.6.8 aot/shells/bash/CMD_SEP.: &str = "__subcmd__"; |