-
Notifications
You must be signed in to change notification settings - Fork 6
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
option for required argument? #5
Comments
If an option is configured to take an argument, the argument is required by default (unless Do you have a specific example where that doesn't behave the way that you want? |
Also, to be clear: are you asking to make an option's argument required (e.g. |
I'm asking for In my case I want this for an int, so it would be |
Currently you'd need to make int required_value = INT_MAX; // Or some other suitable sentinel value.
dropt_option options[] =
{
...
{ '\0', "some_required_option", "description", "ARG", dropt_handle_int, &required_value },
{ 0 }
};
...
char** rest = dropt_parse(droptContext, -1, &argv[1]);
...
if (required_value == INT_MAX)
{
// Print an error and abort.
} If there is no suitable sentinel value, you could handle it as a string and parse it later: char* required_value_str = NULL;
dropt_option options[] =
{
...
{ '\0', "some_required_option", "description", "ARG", dropt_handle_int, &required_value_str },
{ 0 }
};
...
char** rest = dropt_parse(droptContext, -1, &argv[1]);
...
if (required_value_str == NULL)
{
// Print an error and abort.
}
int required_value;
dropt_error error = dropt_handle_int(droptContext, NULL, required_value_str, &required_value);
if (error != dropt_error_none)
{
// Print an error and abort.
} |
I'll spend some time thinking if there's a good way to allow dropt to support required options directly, but I suspect that it will be unlikely. |
Ok thanks! These examples are helpful! |
I'm sorry, but after some deliberation, I've decided not to implement this. In general, required options aren't an isolated feature and have implications on how things like I think ultimately it'd be better to document this scenario with examples, perhaps in an FAQ. |
I am looking for a way to make an argument required. I see the
dropt_attr_optional_val
but can you add a required version?The text was updated successfully, but these errors were encountered: