Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Replace Visibility with Attribute
  • Loading branch information
badaix committed Aug 2, 2021
1 parent f4e0334 commit d8beadd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::string s;

The variable `s` will carry the same value as `string_option.value()`, and thus the declaration of `string_option` can be omitted.

### Visibility of an option
### Attributes of an option

Options have an `Attribute`: they can be hidden in the auto-created help message, or classified as "advanced", or "expert":

Expand All @@ -92,7 +92,7 @@ auto advanced_int = op.add<Value<int>, Attribute::advanced>("i", "integer", "ad
auto hidden_bool = op.add<Swtich, Attribute::hidden>("", "hidden", "hidden flag");
```

Now `cout << op.help()` (same as `cout << op`) will not show the hidden or advanced option, while `cout << op.help(Visibility::advanced)` will show the advanced option. The hidden one is never shown to the user.
Now `cout << op.help()` (same as `cout << op`) will not show the hidden or advanced option, while `cout << op.help(Attribute::advanced)` will show the advanced option. The hidden one is never shown to the user.
Also an option can be flagged as mandatory by assigning `Attribute::required`

## Example
Expand All @@ -112,16 +112,16 @@ int main(int argc, char **argv)
OptionParser op("Allowed options");
auto help_option = op.add<Switch>("h", "help", "produce help message");
auto verbose_option = op.add<Switch>("v", "verbose", "be verbose", &v);
auto hidden_option = op.add<Switch, Visibility::hidden>("x", "", "hidden option");
auto hidden_option = op.add<Switch, Attribute::hidden>("x", "", "hidden option");
auto double_option = op.add<Value<double>>("d", "double", "test for double values", 3.14159265359);
auto float_option = op.add<Value<float>>("f", "float", "test for float values", 2.71828182845f, &f);
op.add<Value<int>>("i", "int", "test for int value w/o option", 23, &i);
auto string_option = op.add<Value<string>>("s", "string", "test for string values");
auto implicit_int_option = op.add<Implicit<int>>("m", "implicit", "implicit test", 42);
auto advanced_option = op.add<Switch, Visibility::advanced>("", "advanced", "advanced option");
auto expert_option = op.add<Switch, Visibility::expert>("", "expert", "expert option");
auto advanced_option = op.add<Switch, Attribute::advanced>("", "advanced", "advanced option");
auto expert_option = op.add<Switch, Attribute::expert>("", "expert", "expert option");
auto inactive_option = op.add<Switch>("", "inactive", "inactive option");
inactive_option->set_visibility(Visibility::inactive);
inactive_option->set_attribute(Attribute::inactive);
implicit_int_option->assign_to(&m);

op.parse(argc, argv);
Expand All @@ -130,9 +130,9 @@ int main(int argc, char **argv)
if (help_option->count() == 1)
cout << op << "\n";
else if (help_option->count() == 2)
cout << op.help(Visibility::advanced) << "\n";
cout << op.help(Attribute::advanced) << "\n";
else if (help_option->count() > 2)
cout << op.help(Visibility::expert) << "\n";
cout << op.help(Attribute::expert) << "\n";

// show all non option arguments (those without "-o" or "--option")
for (const auto& non_option_arg: op.non_option_args())
Expand Down

0 comments on commit d8beadd

Please sign in to comment.