Lines Matching refs:flag
35 // Extracts the flag name from a potential token.
36 // This function only looks for a '=', to split the flag name from the value for
37 // long-form flags. Returns the name of the flag, prefixed with the hyphen(s).
38 inline std::string get_flag_name(const std::string& flag, bool is_short_flag) {
40 return flag;
43 size_t equal_index = flag.find('=');
45 return flag;
47 return flag.substr(0, equal_index);
50 // Parse a boolean flag. Returns `true` if the parsing succeeded, `false`
52 bool parse_bool_flag(Flag<bool>& flag, bool is_short_flag,
55 flag.value() = true;
62 flag.value() = true;
68 flag.value() = true;
73 flag.value() = false;
80 // Parse a uint32_t flag value.
81 bool parse_flag_value(Flag<uint32_t>& flag, const std::string& value) {
103 flag.value() = static_cast<uint32_t>(number);
107 // "Parse" a string flag value (assigns it, cannot fail).
108 bool parse_flag_value(Flag<std::string>& flag, const std::string& value) {
109 flag.value() = value;
113 // Parse a potential multi-token flag. Moves the iterator to the last flag's
114 // token if it's a multi-token flag. Returns `true` if the parsing succeeded.
117 bool parse_flag(Flag<T>& flag, bool is_short_flag, const char*** iterator) {
127 // This is a bi-token flag. Moving iterator to the last parsed token.
131 // This is a mono-token flag, no need to move the iterator.
135 return parse_flag_value(flag, raw_value);
154 static_assert(always_false_v<T>, "Unsupported flag type.");
157 info.flag);
179 // '-' alone is not a flag, but often used to say 'stdin'.
197 std::cerr << "Unknown flag " << raw_flag << std::endl;
207 std::cerr << "Unknown flag " << flag_name << std::endl;
212 std::cerr << "The flag " << flag_name << " was specified multiple times."
219 std::cerr << "Invalid usage for flag " << flag_name << std::endl;
225 for (const auto& flag : get_flags()) {
226 if (!flag.required) {
230 if (parsed_flags.count(&flag) == 0) {
231 std::cerr << "Missing required flag " << flag.name << std::endl;