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

Support prefix style arguments #320

Open
MinekPo1 opened this issue Dec 23, 2023 · 0 comments
Open

Support prefix style arguments #320

MinekPo1 opened this issue Dec 23, 2023 · 0 comments

Comments

@MinekPo1
Copy link

GCC allows for providing arguments to sub-processes via a syntax which I would like to replicate: it uses a prefix as send this to a sub process. As an example -D is used to define a macro (ex -DDEBUG defines a macro named DEBUG).

Currently, at least to my knowledge, such usage is not supported (aside from inheriting from ArgumentParser and implementing it), which is a shame in my opinion.

There are three main ways, that I see, that this feature could be designed as:

  • A modified Argument
  • A separate trait to the ArgumentParser
  • Allowing unknown argument hooks

Modified Argument approach

Example code:

// ...
program.add_argument("--p")
  .make_prefix();
// ...
auto input = program.get<std::string>("--p");
// ...

This would however likely be harder to implement, or would, under the hood, use the second approach anyway.

Separate trait approach

Example code:

// ...
program.add_prefix("--p");
// ...
auto input = program.get<std::string>("--p");
// ...

Slightly more straight-forward to implement, likely would better represent what is happening under the hood, though it seems off to me. It also opens the door for more option related to the prefix, like not using the normal prefix chars.

Hook approach

Example code:

// ...
std::string value;
program.set_unknown_argument_hook([](std::string argument) -> bool {
    if (!argument.substr(0,3) == "--p")
        return false;
    value = argument.substr(3);
    return true;
});
// ...

Likely easiest to implement, and gives room for other creativity, but very hacky feeling and more code needed on the side of the user.

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