7 py::class_<ProgramArguments> py_program_arguments(m,
"ProgramArguments", R
"(
8 Holds the parsed command line arguments of the program.
11 py_program_arguments.def(py::init<>(), R"(
12 Construct an empty set of program arguments.
19 Get all options that are set.
21 :returns: A list of the flags of all options that are set.
26 Check whether an option is set.
28 :param str flag: A flag of the option.
29 :returns: ``True`` if the option is set, ``False`` otherwise.
33 py_program_arguments.def("set_option",
38 Set an option with a single parameter.
40 :param str flag: The flag of the option.
41 :param str parameter: The parameter of the option.
44 py_program_arguments.def("set_option",
47 py::arg(
"parameters"),
49 Set an option with multiple parameters.
51 :param str flag: The flag of the option.
52 :param list[str] parameters: The parameters of the option.
55 py_program_arguments.def("set_option",
58 py::arg(
"equivalent_flags"),
59 py::arg(
"parameters"),
61 Set an option that can be addressed through any of several equivalent flags.
63 :param str flag: The flag of the option.
64 :param set[str] equivalent_flags: All flags that address the same option.
65 :param list[str] parameters: The parameters of the option.
66 :returns: ``True`` on success, ``False`` otherwise.
71 Get the first parameter of an option.
73 :param str flag: A flag of the option.
74 :returns: The parameter, or an empty string if the option is not set.
79 Get all parameters of an option.
81 :param str flag: A flag of the option.
82 :returns: A list of parameters, or an empty list if the option is not set.
86 py::class_<ProgramOptions> py_program_options(m, "ProgramOptions", R
"(
87 Holds the command line options that can be configured from the command line or at runtime using ProgramArguments.
91 Constant to specify that a parameter is required and does not have a default value.
96 py_program_options.def(py::init<const std::string&>(), py::arg("name") = std::string(), R
"(
97 Construct a set of program options.
99 :param str name: The name of this group of program options, used for grouping in ``get_options_string``. Defaults to an empty string.
102 py_program_options.def(
105 std::vector<const char*> argv;
106 argv.reserve(args.size());
107 for (
const auto& arg : args)
109 argv.push_back(arg.c_str());
111 return self.parse((
int)argv.size(), argv.data());
115 Parse the given command line arguments into the internal structure.
116 As on the command line, the first entry is expected to be the name of the program.
118 :param list[str] args: The arguments.
119 :returns: The parsed arguments. The original arguments are not retained.
120 :rtype: hal_py.ProgramArguments
124 Get the command line arguments that could not be parsed.
125 Only valid after ``parse`` was called.
127 :returns: A list of all arguments that could not be parsed.
132 Check whether a flag is already registered for an option.
133 No flag can be registered twice.
135 :param str flag: The flag to check.
136 :returns: ``True`` if the flag is already registered, ``False`` otherwise.
140 py_program_options.def("add",
141 [](
ProgramOptions&
self,
const std::string& flag,
const std::string& description,
const std::vector<std::string>& parameters) {
return self.add_flags({flag}, description, parameters); },
143 py::arg(
"description"),
144 py::arg(
"parameters") = std::vector<std::string>(),
146 Add a new option with a single flag.
147 The length of ``parameters`` is the number of parameters this option takes, its entries are the default values of these parameters.
148 Use ``hal_py.ProgramOptions.A_REQUIRED_PARAMETER`` to mark a parameter as required.
150 :param str flag: The flag activating the option.
151 :param str description: A description of the option.
152 :param list[str] parameters: A list of default values for all parameters. Defaults to an empty list.
153 :returns: ``True`` on success, ``False`` otherwise.
157 py_program_options.def("add",
160 py::arg(
"description"),
161 py::arg(
"parameters") = std::vector<std::string>(),
163 Add a new option with multiple flags.
164 The length of ``parameters`` is the number of parameters this option takes, its entries are the default values of these parameters.
165 Use ``hal_py.ProgramOptions.A_REQUIRED_PARAMETER`` to mark a parameter as required.
167 :param list[str] flags: The flags activating the option.
168 :param str description: A description of the option.
169 :param list[str] parameters: A list of default values for all parameters. Defaults to an empty list.
170 :returns: ``True`` on success, ``False`` otherwise.
174 py_program_options.def("add", py::overload_cast<const ProgramOptions&, const std::string&>(&
ProgramOptions::add), py::arg(
"other_options"), py::arg(
"category") = std::string(), R
"(
175 Add another set of options.
177 :param hal_py.ProgramOptions other_options: The set of options to add.
178 :param str category: A category for the added options, used for grouping in ``get_options_string``. Defaults to an empty string.
179 :returns: ``True`` on success, ``False`` otherwise.
184 Remove a single flag.
185 If multiple flags for an option exist, the others will still remain available.
187 :param str flag: The flag activating the option.
188 :returns: ``True`` if the option was found, ``False`` otherwise.
193 Get a formatted string of all options and their description, including the categories of added options.
194 Useful for usage messages.
196 :returns: The formatted string.
201 Get the flags and the description of all options.
203 :returns: A list of tuples comprising the set of all flags of the option and the description of the option.
204 :rtype: list[tuple(set[str],str)]
std::vector< std::string > get_set_options() const
std::string get_parameter(const std::string &flag) const
std::vector< std::string > get_parameters(const std::string &flag) const
bool is_option_set(const std::string &flag) const
void set_option(const std::string &flag, const std::string ¶meter)
std::string get_options_string() const
bool add_flags(const std::vector< std::string > &flags, const std::string &description, const std::vector< std::string > ¶meters={})
bool is_registered(const std::string &flag) const
bool remove(const std::string &flag)
std::vector< std::tuple< std::set< std::string >, std::string > > get_options() const
bool add(const std::string &flag, const std::string &description, const std::initializer_list< std::string > ¶meters={})
std::vector< std::string > get_unknown_arguments()
static const std::string A_REQUIRED_PARAMETER
constant to specify that a parameter is required and does not have a default value.
void program_options_init(py::module &m)
const Module * module(const Gate *g, const NodeBoxes &boxes)