Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial support for optional arguments #18

Open
halfflat opened this issue Jan 3, 2024 · 0 comments
Open

Partial support for optional arguments #18

halfflat opened this issue Jan 3, 2024 · 0 comments
Assignees

Comments

@halfflat
Copy link
Owner

halfflat commented Jan 3, 2024

If option argument parsing (or end of args testing) is permitted to fail without throwing an exception, we could support optional arguments and options that take different sorts of arguments with e.g.

optional<int> v;
to::opts options[] = {
    { v, "-f", to::lax },
    { to::set(v, 1}, "-f" }
};

trying to parse an integer argument to an option -f to assign to v and then, if it fails to parse an integer, instead just sets v to 1.

Caveats:

  • String arguments are going to be greedy, and would gobble e.g. -- as an argument even if to::lax is given, based on the approach above.
  • The order of options presented to to::run is crucial for this to operate as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant