Revamp ggo help.
[paraslash.git] / ggo.h
1 /*
2 * Copyright (C) 2008-2013 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file ggo.h Functions and structures for help text handling. */
8
9 /**
10 * Information extracted from the .cmdline.h header files.
11 */
12 struct ggo_help {
13 /** Program or module (receiver, filter, writer) name. */
14 const char *prefix;
15 /** Generated by gengetopt from the options in the .ggo file. */
16 const char **short_help;
17 /** Like \a short_help, plus the \a details section. */
18 const char **detailed_help;
19 /** Generated by gengetopt and exported via the *.cmdline.h file. */
20 const char *usage;
21 /** The description text given in the .ggo file. */
22 const char *description;
23 };
24
25 /**
26 * Control the output of \ref ggo_print_help().
27 *
28 * Any combination of these flags may be passed to ggo_print_help().
29 * Note that the list of supported options is always printed.
30 */
31 enum ggo_print_help_flags {
32 /** Whether to print the short help or the detailed help. */
33 GPH_DETAILED = 1 << 0,
34 /** Print the program or module name, git version and codename. */
35 GPH_PRINT_NAME_VERSION = 1 << 1,
36 /** Print the synopsis. */
37 GPH_PRINT_USAGE = 1 << 2,
38 /** Print the description text. */
39 GPH_PRINT_DESCRIPTION = 1 << 3,
40 };
41
42 /** Used to print the normal help of programs (--help) */
43 #define GPH_STANDARD_FLAGS \
44 (GPH_PRINT_NAME_VERSION | GPH_PRINT_USAGE)
45
46 /** Additional information for --detailed-help. */
47 #define GPH_STANDARD_FLAGS_DETAILED \
48 (GPH_STANDARD_FLAGS | GPH_DETAILED | GPH_PRINT_DESCRIPTION)
49
50 /** For module help embedded in a program help. */
51 #define GPH_MODULE_FLAGS 0
52
53 /** Modules help with detailed descriptions. */
54 #define GPH_MODULE_FLAGS_DETAILED GPH_DETAILED | GPH_PRINT_DESCRIPTION
55
56 /** Make a ggo_help structure using information from the .cmdline.h file. */
57 #define DEFINE_GGO_HELP(_prefix) \
58 { \
59 .prefix = #_prefix, \
60 .short_help = _prefix ## _args_info_help, \
61 .detailed_help = _prefix ## _args_info_detailed_help, \
62 .usage = _prefix ## _args_info_usage, \
63 .description = _prefix ## _args_info_description, \
64 }
65
66 void ggo_print_help(struct ggo_help *help, unsigned flags);
67 __printf_1_2 int printf_or_die(const char *fmt, ...);