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

Get invalid option #8

Closed
cattokomo opened this issue Jul 7, 2023 · 2 comments · Fixed by #9
Closed

Get invalid option #8

cattokomo opened this issue Jul 7, 2023 · 2 comments · Fixed by #9

Comments

@cattokomo
Copy link
Contributor

Is there a way to get an invalid option, like an option that doesn't exist in array of cag_option?

while (cag_option_fetch(&context)) {
  ident = cag_option_get(&context);
  switch (ident) {
  case 'h':
    printf("%s\n", "Usage: program [-h]");
    exit(EXIT_SUCCESS);
    break;
  default:
    // here's where it handle invalid option; below is an example
    printf("Error: invalid option '%s'\n", cag_option_get_invalid(&context));
    exit(EXIT_FAILURE);
    break;
  }
}
@likle
Copy link
Owner

likle commented Jul 7, 2023

Hi @UrNightmaree ! ident will be set to '?' if an option is not known.

However, there is currently no API to get the letter/name of the invalid option. You could remember the index from the context before fetching, but that's not ideal. It would actually be fairly easy to implement that here for long names and here for access letters by storing the info in the context. But it's currently not there.

@cattokomo
Copy link
Contributor Author

Does argv[context->index] will get the invalid option?

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

Successfully merging a pull request may close this issue.

2 participants