Skip to content

Commit 9b6d662

Browse files
committed
resolved comments
1 parent eab249e commit 9b6d662

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

docs/dev_notes.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ This will build each test file as a separate executable in the `build/tests/` di
1919

2020
### Run the tests
2121

22-
You can run tests from each test file manually with:
22+
You can run tests from each test file separately with:
2323

2424
```shell
2525
./build/tests/<test-name>
2626
```
2727

28-
where `<test-name>` is the name of the test file without the extension.
29-
30-
To run all tests at once run:
28+
To execute all tests at once run:
3129

3230
```shell
3331
ctest --test-dir build/tests/ # -V (to capture output from each test executable)

docs/tutorial.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,11 @@ The `argument_parser` class also defines the `void parse_args(int argc, char* ar
638638
639639
> [!WARNING]
640640
>
641-
> By default the `argument_parser` class treats all* command-line arguments beggining with a `--` or `-` prefix as optional argument flags and if the flag's value does not match any of the specified arguments, then such flag is considered *unknown* and an exception will be thrown.
641+
> By default the `argument_parser` class treats *all\** command-line arguments beggining with a `--` or `-` prefix as optional argument flags and if the flag's value does not match any of the specified arguments, then such flag is considered *unknown* and an exception will be thrown.
642642
>
643-
> This behaviour can be altered so that the unknown argument flags will be treated as values, not flags.
643+
> *\** If a command-line argument begins with a flag prefix, but contains whitespaces (e.g. `"--flag value"`), then it is treated as a value and not a flag.
644+
>
645+
> This behavior can be altered so that the unknown argument flags will be treated as values, not flags.
644646
>
645647
> Example:
646648
> ```cpp
@@ -796,7 +798,7 @@ int main(int argc, char* argv[]) {
796798
797799
> [!IMPORTANT]
798800
>
799-
> The parser behaviour depends on the argument definitions. The argument parameters are described int the [Argument parameters](#argument-parameters) section.
801+
> The parser's behavior depends on the argument definitions - see [Argument Parameters](#argument-parameters) section.
800802
801803
<br/>
802804
<br/>
@@ -808,14 +810,14 @@ You can retrieve the argument's value with:
808810
809811
```cpp
810812
(const) auto value = parser.value<value_type>("argument_name"); // (1)
811-
(const) auto value = parser.value_or<value_type>("argument_name", default_value); // (2)
813+
(const) auto value = parser.value_or<value_type>("argument_name", fallback_value); // (2)
812814
```
813815
814816
1. This will return the value parsed for the given argument.
815817
816818
For optional arguments this will return the argument's predefined value if no value has been parsed. Additionaly, if more than one value has been parsed for an optional argument, this function will return the first parsed value.
817819
818-
2. When a value has been parsed for the argument, the behaviour is the same as in case **(1)**. Otherwise, this will return `value_type{std::forward<U>(default_value)}` (where `U` is the deducted type of `default_value`), if:
820+
2. When a value has been parsed for the argument, the behavior is the same as in case **(1)**. Otherwise, this will return `value_type{std::forward<U>(fallback_value)}` (where `U` is the deducted type of `fallback_value`), if:
819821
820822
- There is no value parsed for a positional argument
821823
- There is no parsed values and no predefined values for an optional arrument

include/ap/argument_parser.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class argument_parser {
145145
argument::positional<T>& add_positional_argument(std::string_view primary_name) {
146146
this->_verify_arg_name_pattern(primary_name);
147147

148-
const detail::argument_name arg_name = {primary_name};
148+
const detail::argument_name arg_name(primary_name);
149149
if (this->_is_arg_name_used(arg_name))
150150
throw invalid_configuration::argument_name_used(arg_name);
151151

@@ -170,7 +170,7 @@ class argument_parser {
170170
this->_verify_arg_name_pattern(primary_name);
171171
this->_verify_arg_name_pattern(secondary_name);
172172

173-
const detail::argument_name arg_name = {primary_name, secondary_name};
173+
const detail::argument_name arg_name(primary_name, secondary_name);
174174
if (this->_is_arg_name_used(arg_name))
175175
throw invalid_configuration::argument_name_used(arg_name);
176176

@@ -373,12 +373,12 @@ class argument_parser {
373373
* @tparam T Type of the argument value.
374374
* @tparam U The default value type.
375375
* @param arg_name The name of the argument.
376-
* @param default_value The default value.
376+
* @param fallback_value The fallback value.
377377
* @return The value of the argument.
378378
* @throws ap::lookup_failure, ap::type_error
379379
*/
380380
template <detail::c_argument_value_type T = std::string, std::convertible_to<T> U>
381-
[[nodiscard]] T value_or(std::string_view arg_name, U&& default_value) const {
381+
[[nodiscard]] T value_or(std::string_view arg_name, U&& fallback_value) const {
382382
const auto arg_opt = this->_get_argument(arg_name);
383383
if (not arg_opt)
384384
throw lookup_failure::argument_not_found(arg_name);
@@ -390,7 +390,7 @@ class argument_parser {
390390
catch (const std::logic_error&) {
391391
// positional: no value parsed
392392
// optional: no value parsed + no predefined value
393-
return T{std::forward<U>(default_value)};
393+
return T{std::forward<U>(fallback_value)};
394394
}
395395
catch (const std::bad_any_cast& err) {
396396
throw type_error::invalid_value_type(arg_opt->get().name(), typeid(T));
@@ -658,8 +658,11 @@ class argument_parser {
658658
[[nodiscard]] bool _is_valid_flag(const detail::argument_token& tok) const noexcept {
659659
if (tok.type == detail::argument_token::t_flag_primary)
660660
return this->_is_arg_name_used({tok.value}, detail::argument_name::m_primary);
661-
else
661+
662+
if (tok.type == detail::argument_token::t_flag_secondary)
662663
return this->_is_arg_name_used({tok.value}, detail::argument_name::m_secondary);
664+
665+
return false;
663666
}
664667

665668
/**

include/ap/detail/argument_token.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct argument_token {
3838
return this->type == t_flag_primary or this->type == t_flag_secondary;
3939
}
4040

41-
token_type type;
42-
std::string value;
41+
token_type type; ///< The token's type discrimiator value.
42+
std::string value; ///< The actual token's value.
4343
};
4444

4545
} // namespace ap::detail

0 commit comments

Comments
 (0)