Best practice for CLI utility help file

149 views Asked by At

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?

2

There are 2 answers

0
ouah On

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

1
William Pursell On

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