MCPcopy Create free account
hub / github.com/bfgroup/Lyra / cli

Class cli

include/lyra/cli.hpp:54–180  ·  view source on GitHub ↗

tag::reference[] [#lyra_cli] = `lyra::cli` A Combined parser made up of any two or more other parsers. Creating and using one of these as a basis one can incrementally compose other parsers into this one. For example: [source] ---- auto cli = lyra::cli(); std::string what; float when = 0; std::string where; cli |= lyra::opt(what, "what")["--make-it-so"]("Make it so.").required(); cli |= lyra::o

Source from the content-addressed store, hash-verified

52
53*/ // end::reference[]
54class cli : protected arguments
55{
56 public:
57 cli() = default;
58
59 // Copy construction, needs to copy the exe name and the composed parsers.
60 cli(const cli & other);
61
62 // Compose the `exe_name` parser.
63 cli & add_argument(exe_name const & exe_name);
64 cli & operator|=(exe_name const & exe_name);
65
66 // Compose a regular parser.
67 cli & add_argument(parser const & p);
68 cli & operator|=(parser const & p);
69
70 // Compose a group, by adding it as a single argument.
71 cli & add_argument(group const & p);
72 cli & operator|=(group const & p);
73
74 // Compose the parsers from another `cli`.
75 cli & add_argument(cli const & other);
76 cli & operator|=(cli const & other);
77
78 // Result reference wrapper to fetch and convert argument.
79 struct value_result
80 {
81 public:
82 explicit value_result(const parser * p)
83 : parser_ref(p)
84 { }
85
86 template <typename T,
87 typename std::enable_if<detail::is_convertible_from_string<
88 typename detail::remove_cvref<T>::type>::value>::
89 type * = nullptr>
90 operator T() const
91 {
92 typename detail::remove_cvref<T>::type converted_value { };
93 if (parser_ref)
94 detail::from_string<std::string,
95 typename detail::remove_cvref<T>::type>(
96 parser_ref->get_value(0), converted_value);
97 return converted_value;
98 }
99
100 template <typename T>
101 operator std::vector<T>() const
102 {
103 std::vector<T> converted_value;
104 if (parser_ref)
105 {
106 for (std::size_t i = 0; i < parser_ref->get_value_count(); ++i)
107 {
108 T v;
109 if (detail::from_string(parser_ref->get_value(i), v))
110 converted_value.push_back(v);
111 }

Callers 15

operator|Function · 0.70
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
test_valFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls

no outgoing calls

Tested by 15

mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
test_valFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
test_styleFunction · 0.40