29namespace sequoia::parsing::commandline
38 throw std::logic_error{
"Empty string detected"};
45 operator const std::string& ()
const noexcept
51 operator std::string_view()
const noexcept
62 using param_list = std::vector<proper_string>;
63 using arg_list = std::vector<std::string>;
65 using executor = std::function<void (
const arg_list&)>;
101 executor early{}, late{};
102 arg_list arguments{};
106 using options_forest = std::vector<options_tree>;
111 using operations_forest = std::vector<operations_tree>;
120 std::string zeroth_arg;
121 operations_forest operations;
126 std::string error(std::string_view message, std::string_view indent=
" ");
129 std::string error(std::initializer_list<std::string_view> messages, std::string_view indent =
" ");
132 std::string warning(std::string_view message, std::string_view indent=
" ");
135 std::string warning(std::initializer_list<std::string_view> messages, std::string_view indent =
" ");
138 std::string pluralize(std::size_t n, std::string_view noun, std::string_view prefix=
" ");
141 outcome parse(
int argc,
char** argv,
const options_forest& options);
144 template<std::invocable<std::
string> Fn>
146 std::string parse_invoke_depth_first(
int argc,
char** argv,
const options_forest options, Fn zerothArgProcessor)
148 auto[zerothArg, operations, help]{parse(argc, argv, options)};
152 zerothArgProcessor(zerothArg);
154 using namespace maths;
155 for(
const auto& operTree : operations)
157 traverse(depth_first,
159 ignore_disconnected_t{},
160 [&operTree](
const auto node) {
161 const operation& oper{operTree.cbegin_node_weights()[node]};
162 if(oper.early) oper.early(oper.arguments);
164 [&operTree](
const auto node) {
165 const operation& oper{operTree.cbegin_node_weights()[node]};
166 if(oper.late) oper.late(oper.arguments);
184 return {m_ZerothArg, m_Operations, m_Help};
187 enum class top_level { yes, no };
189 struct operation_data
192 std::size_t saturated_args{};
195 operations_forest m_Operations{};
196 int m_Index{1}, m_ArgCount{};
198 std::string m_ZerothArg{}, m_Help{};
200 template<std::input_iterator Iter>
201 void parse(std::ranges::subrange<Iter> options,
const operation_data& previousOperationData, top_level topLevel);
203 template<std::input_iterator Iter>
205 bool process_concatenated_aliases(std::ranges::subrange<Iter> options, std::string_view arg, operation_data currentOperationData, top_level topLevel);
207 auto process_option(
option_tree currentOptionTree, operation_data currentOperationData, top_level topLevel)->operation_data;
209 template<std::input_iterator Iter>
211 static std::string generate_help(std::ranges::subrange<Iter> options);
213 static bool is_alias(
const option& opt, std::string_view s);
Concepts which are sufficiently general to appear in the sequoia namespace.
Restriction of Dynamic Graphs to Trees.
Breadth first, depth first and priority searches.
Definition: DynamicTree.hpp:225
Definition: DynamicTree.hpp:176
Parses command line arguments, building outcome from an option forest.
Definition: CommandLineArguments.hpp:176
Class which wraps a std::string and enforces the invariant that the std::string be non-empty.
Definition: CommandLineArguments.hpp:33
Used to build a forest of operations which will be invoked at the end of the parsing process.
Definition: CommandLineArguments.hpp:100
Used to specify a forest of options, against which the runtime commandline arguments are parsed.
Definition: CommandLineArguments.hpp:80
The result of parsing command line arguments to build an operation forest.
Definition: CommandLineArguments.hpp:119