On 19:31, Lorenzo Bettini wrote:
Wouldn't it be a good thing to use a #define or two in xyz.cmdline.h
which holds the help text?
that's another good idea! :-)
I'll make the help string available so that one can print it anywhere!
I guess the best way would be an array of strings, what do you think?
At the moment we have the following strings that get printed
by cmdline_parser_print_help():
PACKAGE
VERSION
the usage string (e.g. "Usage: xyz [OPTIONS]...")
automatic options (--help, --version)
other options (the real options determined by the .ggo file)
The simple solution I had in mind was to introduce some
macros, (say USAGE, AUTOMATIC_OPTIONS, OTHER_OPTIONS) so that
cmdline_parser_print_help() is equivalent to
printf("%s %s\n", PACKAGE, VERSION);
printf("%s\n\n", USAGE);
printf("%s\n", AUTOMATIC_OPTIONS);
printf("%s\n", OTHER_OPTIONS);
This has the disadvantage that one can only print the help for all
options together.
A more general possibility would be to extend the args_info struct
such that it also contains the help text for each option. For example,
if there is an option called --foo, generate a foo_help member in
args_info, much like foo_given and foo_arg which we already have.
This approach solves the above problem but it makes it difficult to
get the complete help text.
So maybe you are very right and the best way to go is using an array.
We could combine this with the foo_help thing by first doing
const char *args_info_help[] = {
" -h, --help Print help and exit",
" -V, --version Print version and exit"
" -f, --foo set foo (default=`42')",
" -b, --bar set bar (default=`43')",
,,,
}
and then in clear_args()
args_info.foo_help = args_info_help[0];
args_info.bar_help = args_info_help[1];
...
As the help texts may be quite big, we should store it only once
to avoid bloat.
Regards
Andre