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

Add Functionality To Find Unused Commandline Options #88

Open
mcginnie opened this issue Mar 2, 2024 · 2 comments
Open

Add Functionality To Find Unused Commandline Options #88

mcginnie opened this issue Mar 2, 2024 · 2 comments

Comments

@mcginnie
Copy link

mcginnie commented Mar 2, 2024

Many thanks for this library - saved a lot of time!

One feature which I think might be useful is a way to find unused parameters or flags.
As the library returns argument details, that part of the arg string could be marked as used, and then the set of unused things would be available to query.
The utility of this would be in commandline error handling - if at the end of processing you can see unused parameters/flags, that might be evidence of spelling mistakes etc, which can be reported to potentially puzzled users.

@adishavit
Copy link
Owner

I'm glad you are enjoying Argh.

The thing is, that argh does not presume or try to know what args are actually expected, mandatory and/or valid. (Predefined params are mostly meant to automatically distinguish between params (with values) and flags).

It is only interested in parsing the args provided per-run.

It is the user's responsibility to enforce any semantics on the provided args.

@mcginnie mcginnie changed the title Add Functionality To Find Unused Commanline Options Add Functionality To Find Unused Commandline Options Mar 2, 2024
@mcginnie
Copy link
Author

mcginnie commented Mar 2, 2024

Thank you for such a quick response. I understand the agnostic approach - and sympathise.
My thinking is that each datum (flag, parameter name) could be represented by a std::pair<std::string, bool{false}> (rather than just a std::string as now) where the bool is set true on any output access using () or []. It would then be possible to iterate over utilise or unutilised commandline arguments.
This does not impose any interpretation nor semantic rules on the library, but does record what has been used and what not. Since many commandline errors will come from mis-spellings rather than complete novelty, displaying any unused commandline parts will prompt the user in an easily interpreted way (e.g. why is my -file option not used - because it should be -filename).
Doing something similar from outside the library strikes me as considerably more work.

Thank you again.

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

2 participants