Best Practice for CLI Utility Help File

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

Is there any GNU infrastructure I can use for this? If not, I understand that I can do it manually. What is usually considered the best approach?

+4
source share
2 answers

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 what to print on 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
source

argp_parse () is the current gnu structure for parsing arguments. It replaces getopt () and getopt_long (), which should now be considered deprecated.

+1
source

Source: https://habr.com/ru/post/1389745/


All Articles