When writing tools for the CLI of UNIX, how should I make the program print out help and/or usage?
I usually use
fprintf(stderr, "help text here");, but there are several issues with that.
- First, I'm not sure, whether I should use
stderr. Is that OK, or should I use
- As you can imagine, the help text is quite long, depending on how many options the tool has. Now, I usually, just put several
"strings like that\n"in the second parameter. This however, fills my source code with fifty or more lines of help text. It is not easy manageable at all. What should I do instead?
- When a tool is not written in C or a C-like language, I tend to use here-docs where possible (most prominently with Perl). I can't use that in C, but is there something like that, that I could use?
- I was considering putting it in a
#define HELP "help text here", I've never seen it in the wild, don't know whether I should actually use that.
Ideally, I could put the text in an external file, and include it. Using
#include for that seems wrong, though. What should I do then?
The idea is, to have a help text, that is easily manageable. Having it inside the source code isn't really convenient.