4

I've finished implementing a command-line utility that parses arguments via getopt_long. To wrap things up, I need to implement a -h or --help switch that will print out the list of arguments as well as descriptions and default values.

Is there a GNU framework that I can utilize for this? If not, I realize that there are several ways I can do this manually. What's generally seen as the best approach?

Anonymous
  • 1,750
  • 3
  • 16
  • 21

2 Answers2

1

You can use

#include <getopt.h>
int getopt_long(int argc, char * const argv[],
           const char *optstring,
           const struct option *longopts, int *longindex);

See man 3 getopt_long on how to use it.

And on what to print in the output of your --help option, you can read

GNU Coding Standards

4.7.2 ‘--help’

http://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp

ouah
  • 142,963
  • 15
  • 272
  • 331
1

argp_parse() is the current gnu framework for argument parsing. It replaces getopt() and getopt_long(), which should now be considered obsolete.

William Pursell
  • 204,365
  • 48
  • 270
  • 300