-
Notifications
You must be signed in to change notification settings - Fork 125
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
added required options #33
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mcindrich The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign @cofyc |
int flags) | ||
{ | ||
const char *s = NULL; | ||
opt->parsed = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why setting this for all arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I thought it would be the simplest solution to the problem. You set it to 1 for arguments that are used at the command line and at the end of parsing you simply check if the required options have been parsed (meaning used in this context).
@@ -80,14 +84,15 @@ struct argparse_option { | |||
argparse_callback *callback; | |||
intptr_t data; | |||
int flags; | |||
int parsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need this, you define it as a flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how to use this feature, please update test_argparse.c too.
I didn't update test_argparse.c because it would then break the current tests. You use this option by providing OPT_REQUIRED flag to the option flags. For example: |
i like the design of just having to add a flag |
Hi, I added a required options feature by adding a new field parsed to the option struct and a OPT_REQUIRED flag so that every parsed option is checked after parsing so if the option is required and if it doesn't exist the program exits. Unfortunately, by the need to change the field in a struct I had to remove the const attribute of the struct parameters.