Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
options_collector.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <string>
6#include <vector>
7
9 private:
10 std::vector<struct CliOption> merged_long_opts;
11
12 public:
13 void add_options(const CliOption* long_opts) {
14 if (long_opts != nullptr) {
15 for (const CliOption* opt = long_opts; opt->long_name != nullptr; ++opt) {
16 merged_long_opts.push_back(*opt);
17 }
18 }
19 }
20
21 Step make_parse_step(int argc, char* argv[]) {
22 return [=](Context& ctx) {
23 merged_long_opts.push_back(OPTION_END);
24
25 opterr = 0;
26 char** cmd_argv = argv + 1;
27 int cmd_argc = argc - 1;
28 return parse_options(cmd_argc, cmd_argv, merged_long_opts, ctx.options);
29 };
30 }
31
32 const std::vector<CliOption>& get_options() const {
33 return merged_long_opts;
34 }
35};
void add_options(const CliOption *long_opts)
Step make_parse_step(int argc, char *argv[])
const std::vector< CliOption > & get_options() const
Main command orchestration interface.
std::function< bool(Context &)> Step
bool parse_options(int argc, char *argv[], const std::vector< CliOption > &options, ParsedOptions &ctx_options)
Analyzes command-line arguments and populates ParsedOptions.
#define OPTION_END
This marks the end of a long array of options.
const char * long_name