ArgsParser.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /*
  2. * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
  3. * Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include "AK/JsonObject.h"
  8. #include <AK/Format.h>
  9. #include <AK/StringBuilder.h>
  10. #include <LibCore/ArgsParser.h>
  11. #include <LibCore/Version.h>
  12. #include <getopt.h>
  13. #include <limits.h>
  14. #include <math.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. static Optional<double> convert_to_double(const char* s)
  18. {
  19. char* p;
  20. double v = strtod(s, &p);
  21. if (isnan(v) || p == s)
  22. return {};
  23. return v;
  24. }
  25. namespace Core {
  26. ArgsParser::ArgsParser()
  27. {
  28. add_option(m_show_help, "Display help message and exit", "help", 0, true);
  29. add_option(m_show_version, "Print version", "version", 0, true);
  30. add_option(m_perform_autocomplete, "Perform autocompletion", "complete", 0, true);
  31. }
  32. bool ArgsParser::parse(int argc, char* const* argv, FailureBehavior failure_behavior)
  33. {
  34. auto fail = [this, argv, failure_behavior] {
  35. if (failure_behavior == FailureBehavior::PrintUsage || failure_behavior == FailureBehavior::PrintUsageAndExit)
  36. print_usage(stderr, argv[0]);
  37. if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
  38. exit(1);
  39. };
  40. Vector<option> long_options;
  41. StringBuilder short_options_builder;
  42. if (m_stop_on_first_non_option)
  43. short_options_builder.append('+');
  44. int index_of_found_long_option = -1;
  45. // Tell getopt() to reset its internal state, and start scanning from optind = 1.
  46. // We could also set optreset = 1, but the host platform may not support that.
  47. optind = 0;
  48. for (size_t i = 0; i < m_options.size(); i++) {
  49. auto& opt = m_options[i];
  50. if (opt.long_name) {
  51. option long_opt {
  52. opt.long_name,
  53. opt.requires_argument ? required_argument : no_argument,
  54. &index_of_found_long_option,
  55. static_cast<int>(i)
  56. };
  57. long_options.append(long_opt);
  58. }
  59. if (opt.short_name) {
  60. short_options_builder.append(opt.short_name);
  61. if (opt.requires_argument)
  62. short_options_builder.append(':');
  63. }
  64. }
  65. long_options.append({ 0, 0, 0, 0 });
  66. String short_options = short_options_builder.build();
  67. while (true) {
  68. int c = getopt_long(argc, argv, short_options.characters(), long_options.data(), nullptr);
  69. if (c == -1) {
  70. // We have reached the end.
  71. break;
  72. } else if (c == '?') {
  73. // There was an error, and getopt() has already
  74. // printed its error message.
  75. fail();
  76. return false;
  77. }
  78. // Let's see what option we just found.
  79. Option* found_option = nullptr;
  80. if (c == 0) {
  81. // It was a long option.
  82. VERIFY(index_of_found_long_option >= 0);
  83. found_option = &m_options[index_of_found_long_option];
  84. index_of_found_long_option = -1;
  85. } else {
  86. // It was a short option, look it up.
  87. auto it = m_options.find_if([c](auto& opt) { return c == opt.short_name; });
  88. VERIFY(!it.is_end());
  89. found_option = &*it;
  90. }
  91. VERIFY(found_option);
  92. const char* arg = found_option->requires_argument ? optarg : nullptr;
  93. if (!found_option->accept_value(arg)) {
  94. warnln("\033[31mInvalid value for option \033[1m{}\033[22m\033[0m", found_option->name_for_display());
  95. fail();
  96. return false;
  97. }
  98. }
  99. // We're done processing options.
  100. // Now let's show version or help if requested, or perform autocompletion if needed.
  101. if (m_show_version) {
  102. print_version(stdout);
  103. if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
  104. exit(0);
  105. return false;
  106. }
  107. if (m_show_help) {
  108. print_usage(stdout, argv[0]);
  109. if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
  110. exit(0);
  111. return false;
  112. }
  113. if (m_perform_autocomplete) {
  114. autocomplete(stdout, argv[0], Span<char const* const> { argv + optind, static_cast<size_t>(argc - optind) });
  115. if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
  116. exit(0);
  117. return false;
  118. }
  119. // Now let's parse positional arguments.
  120. int values_left = argc - optind;
  121. Vector<int, 16> num_values_for_arg;
  122. num_values_for_arg.resize(m_positional_args.size(), true);
  123. int total_values_required = 0;
  124. for (size_t i = 0; i < m_positional_args.size(); i++) {
  125. auto& arg = m_positional_args[i];
  126. num_values_for_arg[i] = arg.min_values;
  127. total_values_required += arg.min_values;
  128. }
  129. if (total_values_required > values_left) {
  130. fail();
  131. return false;
  132. }
  133. int extra_values_to_distribute = values_left - total_values_required;
  134. for (size_t i = 0; i < m_positional_args.size(); i++) {
  135. auto& arg = m_positional_args[i];
  136. int extra_values_to_this_arg = min(arg.max_values - arg.min_values, extra_values_to_distribute);
  137. num_values_for_arg[i] += extra_values_to_this_arg;
  138. extra_values_to_distribute -= extra_values_to_this_arg;
  139. if (extra_values_to_distribute == 0)
  140. break;
  141. }
  142. if (extra_values_to_distribute > 0) {
  143. // We still have too many values :(
  144. fail();
  145. return false;
  146. }
  147. for (size_t i = 0; i < m_positional_args.size(); i++) {
  148. auto& arg = m_positional_args[i];
  149. for (int j = 0; j < num_values_for_arg[i]; j++) {
  150. const char* value = argv[optind++];
  151. if (!arg.accept_value(value)) {
  152. warnln("Invalid value for argument {}", arg.name);
  153. fail();
  154. return false;
  155. }
  156. }
  157. }
  158. return true;
  159. }
  160. void ArgsParser::print_usage(FILE* file, const char* argv0)
  161. {
  162. char const* env_preference = getenv("ARGSPARSER_EMIT_MARKDOWN");
  163. if (env_preference != nullptr && env_preference[0] == '1' && env_preference[1] == 0) {
  164. print_usage_markdown(file, argv0);
  165. } else {
  166. print_usage_terminal(file, argv0);
  167. }
  168. }
  169. void ArgsParser::print_usage_terminal(FILE* file, const char* argv0)
  170. {
  171. out(file, "Usage:\n\t\033[1m{}\033[0m", argv0);
  172. for (auto& opt : m_options) {
  173. if (opt.hide_from_help_and_autocomplete)
  174. continue;
  175. if (opt.requires_argument)
  176. out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
  177. else
  178. out(file, " [{}]", opt.name_for_display());
  179. }
  180. for (auto& arg : m_positional_args) {
  181. bool required = arg.min_values > 0;
  182. bool repeated = arg.max_values > 1;
  183. if (required && repeated)
  184. out(file, " <{}...>", arg.name);
  185. else if (required && !repeated)
  186. out(file, " <{}>", arg.name);
  187. else if (!required && repeated)
  188. out(file, " [{}...]", arg.name);
  189. else if (!required && !repeated)
  190. out(file, " [{}]", arg.name);
  191. }
  192. outln(file);
  193. if (m_general_help != nullptr && m_general_help[0] != '\0') {
  194. outln(file, "\nDescription:");
  195. outln(file, "{}", m_general_help);
  196. }
  197. if (!m_options.is_empty())
  198. outln(file, "\nOptions:");
  199. for (auto& opt : m_options) {
  200. auto print_argument = [&]() {
  201. if (opt.value_name) {
  202. if (opt.requires_argument)
  203. out(file, " {}", opt.value_name);
  204. else
  205. out(file, " [{}]", opt.value_name);
  206. }
  207. };
  208. out(file, "\t");
  209. if (opt.short_name) {
  210. out(file, "\033[1m-{}\033[0m", opt.short_name);
  211. print_argument();
  212. }
  213. if (opt.short_name && opt.long_name)
  214. out(file, ", ");
  215. if (opt.long_name) {
  216. out(file, "\033[1m--{}\033[0m", opt.long_name);
  217. print_argument();
  218. }
  219. if (opt.help_string)
  220. out(file, "\t{}", opt.help_string);
  221. outln(file);
  222. }
  223. if (!m_positional_args.is_empty())
  224. outln(file, "\nArguments:");
  225. for (auto& arg : m_positional_args) {
  226. out(file, "\t\033[1m{}\033[0m", arg.name);
  227. if (arg.help_string)
  228. out(file, "\t{}", arg.help_string);
  229. outln(file);
  230. }
  231. }
  232. void ArgsParser::print_usage_markdown(FILE* file, const char* argv0)
  233. {
  234. outln(file, "## Name\n\n{}", argv0);
  235. out(file, "\n## Synopsis\n\n```sh\n$ {}", argv0);
  236. for (auto& opt : m_options) {
  237. if (opt.hide_from_help_and_autocomplete)
  238. continue;
  239. if (opt.requires_argument)
  240. out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
  241. else
  242. out(file, " [{}]", opt.name_for_display());
  243. }
  244. for (auto& arg : m_positional_args) {
  245. bool required = arg.min_values > 0;
  246. bool repeated = arg.max_values > 1;
  247. if (required && repeated)
  248. out(file, " <{}...>", arg.name);
  249. else if (required && !repeated)
  250. out(file, " <{}>", arg.name);
  251. else if (!required && repeated)
  252. out(file, " [{}...]", arg.name);
  253. else if (!required && !repeated)
  254. out(file, " [{}]", arg.name);
  255. }
  256. outln(file, "\n```");
  257. if (m_general_help != nullptr && m_general_help[0] != '\0') {
  258. outln(file, "\n## Description\n\n{}", m_general_help);
  259. }
  260. if (!m_options.is_empty())
  261. outln(file, "\n## Options:\n");
  262. for (auto& opt : m_options) {
  263. auto print_argument = [&]() {
  264. if (opt.value_name != nullptr) {
  265. if (opt.requires_argument)
  266. out(file, " {}", opt.value_name);
  267. else
  268. out(file, " [{}]", opt.value_name);
  269. }
  270. };
  271. out(file, "* ");
  272. if (opt.short_name != '\0') {
  273. out(file, "`-{}", opt.short_name);
  274. print_argument();
  275. out(file, "`");
  276. }
  277. if (opt.short_name != '\0' && opt.long_name != nullptr)
  278. out(file, ", ");
  279. if (opt.long_name != nullptr) {
  280. out(file, "`--{}", opt.long_name);
  281. print_argument();
  282. out(file, "`");
  283. }
  284. if (opt.help_string != nullptr)
  285. out(file, ": {}", opt.help_string);
  286. outln(file);
  287. }
  288. if (!m_positional_args.is_empty())
  289. outln(file, "\n## Arguments:\n");
  290. for (auto& arg : m_positional_args) {
  291. out(file, "* `{}`", arg.name);
  292. if (arg.help_string != nullptr)
  293. out(file, ": {}", arg.help_string);
  294. outln(file);
  295. }
  296. }
  297. void ArgsParser::print_version(FILE* file)
  298. {
  299. outln(file, Core::Version::SERENITY_VERSION);
  300. }
  301. void ArgsParser::add_option(Option&& option)
  302. {
  303. m_options.append(move(option));
  304. }
  305. void ArgsParser::add_ignored(const char* long_name, char short_name, bool hidden)
  306. {
  307. Option option {
  308. false,
  309. "Ignored",
  310. long_name,
  311. short_name,
  312. nullptr,
  313. [](const char*) {
  314. return true;
  315. },
  316. hidden,
  317. };
  318. add_option(move(option));
  319. }
  320. void ArgsParser::add_option(bool& value, const char* help_string, const char* long_name, char short_name, bool hidden)
  321. {
  322. Option option {
  323. false,
  324. help_string,
  325. long_name,
  326. short_name,
  327. nullptr,
  328. [&value](const char* s) {
  329. VERIFY(s == nullptr);
  330. value = true;
  331. return true;
  332. },
  333. hidden,
  334. };
  335. add_option(move(option));
  336. }
  337. void ArgsParser::add_option(const char*& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  338. {
  339. Option option {
  340. true,
  341. help_string,
  342. long_name,
  343. short_name,
  344. value_name,
  345. [&value](const char* s) {
  346. value = s;
  347. return true;
  348. },
  349. hidden,
  350. };
  351. add_option(move(option));
  352. }
  353. void ArgsParser::add_option(String& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  354. {
  355. Option option {
  356. true,
  357. help_string,
  358. long_name,
  359. short_name,
  360. value_name,
  361. [&value](const char* s) {
  362. value = s;
  363. return true;
  364. },
  365. hidden,
  366. };
  367. add_option(move(option));
  368. }
  369. void ArgsParser::add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
  370. {
  371. Option option {
  372. true,
  373. help_string,
  374. long_name,
  375. short_name,
  376. value_name,
  377. [&value](const char* s) {
  378. value = s;
  379. return true;
  380. },
  381. hidden,
  382. };
  383. add_option(move(option));
  384. }
  385. void ArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  386. {
  387. Option option {
  388. true,
  389. help_string,
  390. long_name,
  391. short_name,
  392. value_name,
  393. [&value](const char* s) {
  394. auto opt = StringView(s).to_int();
  395. value = opt.value_or(0);
  396. return opt.has_value();
  397. },
  398. hidden,
  399. };
  400. add_option(move(option));
  401. }
  402. void ArgsParser::add_option(unsigned& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  403. {
  404. Option option {
  405. true,
  406. help_string,
  407. long_name,
  408. short_name,
  409. value_name,
  410. [&value](const char* s) {
  411. auto opt = StringView(s).to_uint();
  412. value = opt.value_or(0);
  413. return opt.has_value();
  414. },
  415. hidden,
  416. };
  417. add_option(move(option));
  418. }
  419. void ArgsParser::add_option(double& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  420. {
  421. Option option {
  422. true,
  423. help_string,
  424. long_name,
  425. short_name,
  426. value_name,
  427. [&value](const char* s) {
  428. auto opt = convert_to_double(s);
  429. value = opt.value_or(0.0);
  430. return opt.has_value();
  431. },
  432. hidden,
  433. };
  434. add_option(move(option));
  435. }
  436. void ArgsParser::add_option(Optional<double>& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  437. {
  438. Option option {
  439. true,
  440. help_string,
  441. long_name,
  442. short_name,
  443. value_name,
  444. [&value](const char* s) {
  445. value = convert_to_double(s);
  446. return value.has_value();
  447. },
  448. hidden,
  449. };
  450. add_option(move(option));
  451. }
  452. void ArgsParser::add_option(Optional<size_t>& value, const char* help_string, const char* long_name, char short_name, const char* value_name, bool hidden)
  453. {
  454. Option option {
  455. true,
  456. help_string,
  457. long_name,
  458. short_name,
  459. value_name,
  460. [&value](const char* s) {
  461. value = AK::StringUtils::convert_to_uint<size_t>(s);
  462. return value.has_value();
  463. },
  464. hidden,
  465. };
  466. add_option(move(option));
  467. }
  468. void ArgsParser::add_positional_argument(Arg&& arg)
  469. {
  470. m_positional_args.append(move(arg));
  471. }
  472. void ArgsParser::add_positional_argument(const char*& value, const char* help_string, const char* name, Required required)
  473. {
  474. Arg arg {
  475. help_string,
  476. name,
  477. required == Required::Yes ? 1 : 0,
  478. 1,
  479. [&value](const char* s) {
  480. value = s;
  481. return true;
  482. }
  483. };
  484. add_positional_argument(move(arg));
  485. }
  486. void ArgsParser::add_positional_argument(String& value, const char* help_string, const char* name, Required required)
  487. {
  488. Arg arg {
  489. help_string,
  490. name,
  491. required == Required::Yes ? 1 : 0,
  492. 1,
  493. [&value](const char* s) {
  494. value = s;
  495. return true;
  496. }
  497. };
  498. add_positional_argument(move(arg));
  499. }
  500. void ArgsParser::add_positional_argument(StringView& value, char const* help_string, char const* name, Required required)
  501. {
  502. Arg arg {
  503. help_string,
  504. name,
  505. required == Required::Yes ? 1 : 0,
  506. 1,
  507. [&value](const char* s) {
  508. value = s;
  509. return true;
  510. }
  511. };
  512. add_positional_argument(move(arg));
  513. }
  514. void ArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required)
  515. {
  516. Arg arg {
  517. help_string,
  518. name,
  519. required == Required::Yes ? 1 : 0,
  520. 1,
  521. [&value](const char* s) {
  522. auto opt = StringView(s).to_int();
  523. value = opt.value_or(0);
  524. return opt.has_value();
  525. }
  526. };
  527. add_positional_argument(move(arg));
  528. }
  529. void ArgsParser::add_positional_argument(unsigned& value, const char* help_string, const char* name, Required required)
  530. {
  531. Arg arg {
  532. help_string,
  533. name,
  534. required == Required::Yes ? 1 : 0,
  535. 1,
  536. [&value](const char* s) {
  537. auto opt = StringView(s).to_uint();
  538. value = opt.value_or(0);
  539. return opt.has_value();
  540. }
  541. };
  542. add_positional_argument(move(arg));
  543. }
  544. void ArgsParser::add_positional_argument(double& value, const char* help_string, const char* name, Required required)
  545. {
  546. Arg arg {
  547. help_string,
  548. name,
  549. required == Required::Yes ? 1 : 0,
  550. 1,
  551. [&value](const char* s) {
  552. auto opt = convert_to_double(s);
  553. value = opt.value_or(0.0);
  554. return opt.has_value();
  555. }
  556. };
  557. add_positional_argument(move(arg));
  558. }
  559. void ArgsParser::add_positional_argument(Vector<const char*>& values, const char* help_string, const char* name, Required required)
  560. {
  561. Arg arg {
  562. help_string,
  563. name,
  564. required == Required::Yes ? 1 : 0,
  565. INT_MAX,
  566. [&values](const char* s) {
  567. values.append(s);
  568. return true;
  569. }
  570. };
  571. add_positional_argument(move(arg));
  572. }
  573. void ArgsParser::add_positional_argument(Vector<StringView>& values, char const* help_string, char const* name, Required required)
  574. {
  575. Arg arg {
  576. help_string,
  577. name,
  578. required == Required::Yes ? 1 : 0,
  579. INT_MAX,
  580. [&values](char const* s) {
  581. values.append(s);
  582. return true;
  583. }
  584. };
  585. add_positional_argument(move(arg));
  586. }
  587. void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char const* const> remaining_arguments)
  588. {
  589. // We expect the full invocation of the program to be available as positional args,
  590. // e.g. `foo --bar arg -b` (program invoked as `foo --complete -- foo --bar arg -b`)
  591. auto first = true;
  592. auto seen_all_options = false;
  593. auto skip_next = false;
  594. StringView argument_to_complete;
  595. StringView option_to_complete;
  596. auto completing_option = false;
  597. for (auto& arg : remaining_arguments) {
  598. StringView argument { arg };
  599. completing_option = false;
  600. if (skip_next) {
  601. argument_to_complete = argument;
  602. skip_next = false;
  603. continue;
  604. }
  605. // Skip over the program name.
  606. if (first && program_name == argument) {
  607. first = false;
  608. continue;
  609. }
  610. if (seen_all_options) {
  611. argument_to_complete = argument;
  612. continue;
  613. }
  614. if (argument.starts_with("--")) {
  615. option_to_complete = argument;
  616. completing_option = true;
  617. if (argument == "--") {
  618. seen_all_options = true;
  619. continue;
  620. }
  621. // Look for a long option
  622. auto option_pattern = argument.substring_view(2);
  623. auto it = m_options.find_if([&](auto& option) { return !option.hide_from_help_and_autocomplete && StringView(option.long_name) == option_pattern; });
  624. if (it.is_end())
  625. continue;
  626. if (it->requires_argument)
  627. skip_next = true;
  628. continue;
  629. }
  630. if (argument.starts_with("-")) {
  631. option_to_complete = argument;
  632. completing_option = true;
  633. if (argument == "-") {
  634. option_to_complete = argument;
  635. continue;
  636. }
  637. // Look for a short option
  638. auto option_pattern = argument[argument.length() - 1];
  639. auto it = m_options.find_if([&](auto& option) { return !option.hide_from_help_and_autocomplete && option.short_name == option_pattern; });
  640. if (it.is_end())
  641. continue;
  642. if (it->requires_argument)
  643. skip_next = true;
  644. continue;
  645. }
  646. }
  647. // We don't know how to complete arguments quite yet.
  648. if (!completing_option)
  649. return;
  650. auto write_completion = [&](auto format, auto& option, auto... args) {
  651. JsonObject object;
  652. object.set("completion", String::formatted(format, args...));
  653. object.set("static_offset", 0);
  654. object.set("invariant_offset", option_to_complete.length());
  655. object.set("display_trivia", option.help_string);
  656. object.set("trailing_trivia", option.requires_argument ? " " : "");
  657. outln(file, "{}", object.to_string());
  658. };
  659. if (option_to_complete.starts_with("--")) {
  660. // Complete a long option.
  661. auto option_pattern = option_to_complete.substring_view(2);
  662. for (auto& option : m_options) {
  663. if (option.hide_from_help_and_autocomplete)
  664. continue;
  665. StringView option_string = option.long_name;
  666. if (option_string.starts_with(option_pattern)) {
  667. write_completion("--{}", option, option_string);
  668. }
  669. }
  670. } else {
  671. // Complete a short option, note that we're not going to attempt to 'match' anything here.
  672. for (auto& option : m_options) {
  673. if (option.hide_from_help_and_autocomplete)
  674. continue;
  675. if (option.short_name == 0)
  676. continue;
  677. write_completion("-{}", option, option.short_name);
  678. }
  679. }
  680. }
  681. }