tag::reference[] [#lyra_command] = `lyra::command` A parser that encapsulates the pattern of parsing sub-commands. It provides a quick wrapper for the equivalent arrangement of `group` and `literal` parsers. For example: [source] ---- lyra::command c = lyra::command("sub"); ---- Is equivalent to: [source] ---- lyra::command c = lyra::group() .sequential() .add_argument(literal("sub")) .add
| 49 | |
| 50 | */ // end::reference[] |
| 51 | class command : public group |
| 52 | { |
| 53 | public: |
| 54 | // Construction, with and without, callback. |
| 55 | explicit command(const std::string & n); |
| 56 | command( |
| 57 | const std::string & n, const std::function<void(const group &)> & f); |
| 58 | |
| 59 | // Help description. |
| 60 | command & help(const std::string & text); |
| 61 | command & operator()(std::string const & description); |
| 62 | |
| 63 | // Add arguments. |
| 64 | template <typename P> |
| 65 | command & add_argument(P const & p); |
| 66 | template <typename P> |
| 67 | command & operator|=(P const & p); |
| 68 | |
| 69 | // Settings. |
| 70 | command & brief_help(bool brief = true); |
| 71 | command & optional() { return static_cast<command &>(group::optional()); } |
| 72 | command & required(std::size_t n = 1) |
| 73 | { |
| 74 | return static_cast<command &>(group::required(n)); |
| 75 | } |
| 76 | command & cardinality(std::size_t n) |
| 77 | { |
| 78 | return static_cast<command &>(group::cardinality(n)); |
| 79 | } |
| 80 | command & cardinality(std::size_t n, std::size_t m) |
| 81 | { |
| 82 | return static_cast<command &>(group::cardinality(n, m)); |
| 83 | } |
| 84 | |
| 85 | // Internal. |
| 86 | std::unique_ptr<parser> clone() const override |
| 87 | { |
| 88 | return make_clone<command>(this); |
| 89 | } |
| 90 | detail::parser_cardinality cardinality() const override |
| 91 | { |
| 92 | return group::cardinality(); |
| 93 | } |
| 94 | |
| 95 | std::string get_usage_text(const option_style & style) const override |
| 96 | { |
| 97 | auto tail = parsers[1]->get_usage_text(style); |
| 98 | return parsers[0]->get_usage_text(style) |
| 99 | + (tail.empty() ? (tail) : (" " + tail)); |
| 100 | } |
| 101 | |
| 102 | protected: |
| 103 | bool expanded_help_details = true; |
| 104 | |
| 105 | std::string get_print_order_key(const option_style & style) const override |
| 106 | { |
| 107 | return parsers[0]->get_print_order_key(style); |
| 108 | } |
no outgoing calls