| 173 | } |
| 174 | |
| 175 | void TZshCompletionGenerator::GenerateOptsCompletion(TFormattedOutput& out, const TOpts& opts, NComp::TCompleterManager& manager) { |
| 176 | L << "_arguments -s \\"; |
| 177 | { |
| 178 | I; |
| 179 | |
| 180 | if (opts.ArgPermutation_ == EArgPermutation::REQUIRE_ORDER) { |
| 181 | L << "-S \\"; |
| 182 | } |
| 183 | |
| 184 | for (auto opt: opts.GetOpts()) { |
| 185 | if (!opt->Hidden_) { |
| 186 | GenerateOptCompletion(out, opts, *opt, manager); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | auto argSpecs = opts.GetFreeArgSpecs(); |
| 191 | size_t numFreeArgs = opts.GetFreeArgsMax(); |
| 192 | bool unlimitedArgs = false; |
| 193 | if (numFreeArgs == TOpts::UNLIMITED_ARGS) { |
| 194 | numFreeArgs = argSpecs.empty() ? 0 : (argSpecs.rbegin()->first + 1); |
| 195 | unlimitedArgs = true; |
| 196 | } |
| 197 | |
| 198 | for (size_t i = 0; i < numFreeArgs; ++i) { |
| 199 | auto& spec = argSpecs[i]; |
| 200 | auto& line = L << "'" << (i + 1) << ":"; |
| 201 | if (spec.IsOptional()) { |
| 202 | line << ":"; |
| 203 | } |
| 204 | auto argHelp = spec.GetCompletionArgHelp(opts.GetDefaultFreeArgTitle()); |
| 205 | if (argHelp) { |
| 206 | line << Q(argHelp); |
| 207 | } else { |
| 208 | line << " "; |
| 209 | } |
| 210 | line << ":"; |
| 211 | if (spec.Completer_) { |
| 212 | line << spec.Completer_->GenerateZshAction(manager); |
| 213 | } else { |
| 214 | line << "_default"; |
| 215 | } |
| 216 | line << "' \\"; |
| 217 | } |
| 218 | |
| 219 | if (unlimitedArgs) { |
| 220 | auto& spec = opts.GetTrailingArgSpec(); |
| 221 | auto& line = L << "'*:"; |
| 222 | auto argHelp = spec.GetCompletionArgHelp(opts.GetDefaultFreeArgTitle()); |
| 223 | if (argHelp) { |
| 224 | line << Q(argHelp); |
| 225 | } else { |
| 226 | line << " "; |
| 227 | } |
| 228 | line << ":"; |
| 229 | if (spec.Completer_) { |
| 230 | line << spec.Completer_->GenerateZshAction(manager); |
| 231 | } else { |
| 232 | line << "_default"; |
nothing calls this directly
no test coverage detected