typedef typedefG_BEGIN_DECLS struct _GOptionContext | GOptionContext |
typedef struct _GOptionGroup | GOptionGroup |
typedef struct _GOptionEntry | GOptionEntry |
Enumerator | Value | Description |
---|---|---|
G_OPTION_FLAG_HIDDEN | 1 << 0 | |
G_OPTION_FLAG_IN_MAIN | 1 << 1 | |
G_OPTION_FLAG_REVERSE | 1 << 2 | |
G_OPTION_FLAG_NO_ARG | 1 << 3 | |
G_OPTION_FLAG_FILENAME | 1 << 4 | |
G_OPTION_FLAG_OPTIONAL_ARG | 1 << 5 | |
G_OPTION_FLAG_NOALIAS | 1 << 6 |
typedef gboolean(* | GOptionArgFunc |
typedef gboolean(* | GOptionParseFunc |
typedef void(* | GOptionErrorFunc |
Enumerator | Value | Description |
---|---|---|
G_OPTION_ERROR_UNKNOWN_OPTION | ||
G_OPTION_ERROR_BAD_VALUE | ||
G_OPTION_ERROR_FAILED |
IMPORT_C GQuark | g_option_error_quark | ( | void | ) |
IMPORT_C GOptionContext * | g_option_context_new | ( | const gchar * | parameter_string | ) |
g_option_context_new: : a string which is displayed in the first line of <option>--help</option> output, after the usage summary <literal><replaceable>programname</replaceable> [OPTION...]</literal>
Creates a new option context.
The can serve multiple purposes. It can be used to add descriptions for "rest" arguments, which are not parsed by the GOptionContext, typically something like "FILES" or "FILE1 FILE2...". If you are using G_OPTION_REMAINING for collecting "rest" arguments, GLib handles this automatically by using the of the corresponding GOptionEntry in the usage summary.
Another usage is to give a short summary of the program functionality, like " - frob the strings", which will be displayed in the same line as the usage. For a longer description of the program functionality that should be displayed as a paragraph below the usage line, use g_option_context_set_summary().
Note that the is translated using the function set with g_option_context_set_translate_func(), so it should normally be passed untranslated.
Returns: a newly created GOptionContext, which must be freed with g_option_context_free() after use.
Since: 2.6
IMPORT_C void | g_option_context_set_summary | ( | GOptionContext * | context, |
const gchar * | summary | |||
) |
g_option_context_set_summary: : a GOptionContext : a string to be shown in <option>--help</option> output before the list of options, or NULL
Adds a string to be displayed in <option>--help</option> output before the list of options. This is typically a summary of the program functionality.
Note that the summary is translated (see g_option_context_set_translate_func() and g_option_context_set_translation_domain()).
Since: 2.12
IMPORT_C G_CONST_RETURN gchar * | g_option_context_get_summary | ( | GOptionContext * | context | ) |
g_option_context_get_summary: : a GOptionContext
Returns the summary. See g_option_context_set_summary().
Returns: the summary
Since: 2.12
IMPORT_C void | g_option_context_set_description | ( | GOptionContext * | context, |
const gchar * | description | |||
) |
g_option_context_set_description: : a GOptionContext : a string to be shown in <option>--help</option> output after the list of options, or NULL
Adds a string to be displayed in <option>--help</option> output after the list of options. This text often includes a bug reporting address.
Note that the summary is translated (see g_option_context_set_translate_func()).
Since: 2.12
IMPORT_C G_CONST_RETURN gchar * | g_option_context_get_description | ( | GOptionContext * | context | ) |
g_option_context_get_description: : a GOptionContext
Returns the description. See g_option_context_set_description().
Returns: the description
Since: 2.12
IMPORT_C void | g_option_context_free | ( | GOptionContext * | context | ) |
g_option_context_free: : a GOptionContext
Frees context and all the groups which have been added to it.
Since: 2.6
IMPORT_C void | g_option_context_set_help_enabled | ( | GOptionContext * | context, |
gboolean | help_enabled | |||
) |
g_option_context_set_help_enabled: : a GOptionContext : TRUE to enable <option>--help</option>, FALSE to disable it
Enables or disables automatic generation of <option>--help</option> output. By default, g_option_context_parse() recognizes <option>--help</option>, <option>-?</option>, <option>--help-all</option> and <option>--help-</option><replaceable>groupname</replaceable> and creates suitable output to stdout.
Since: 2.6
IMPORT_C gboolean | g_option_context_get_help_enabled | ( | GOptionContext * | context | ) |
g_option_context_get_help_enabled: : a GOptionContext
Returns whether automatic <option>--help</option> generation is turned on for . See g_option_context_set_help_enabled().
Returns: TRUE if automatic help generation is turned on.
Since: 2.6
IMPORT_C void | g_option_context_set_ignore_unknown_options | ( | GOptionContext * | context, |
gboolean | ignore_unknown | |||
) |
g_option_context_set_ignore_unknown_options: : a GOptionContext : TRUE to ignore unknown options, FALSE to produce an error when unknown options are met
Sets whether to ignore unknown options or not. If an argument is ignored, it is left in the array after parsing. By default, g_option_context_parse() treats unknown options as error.
This setting does not affect non-option arguments (i.e. arguments which don't start with a dash). But note that GOption cannot reliably determine whether a non-option belongs to a preceding unknown option.
Since: 2.6
IMPORT_C gboolean | g_option_context_get_ignore_unknown_options | ( | GOptionContext * | context | ) |
g_option_context_get_ignore_unknown_options: : a GOptionContext
Returns whether unknown options are ignored or not. See g_option_context_set_ignore_unknown_options().
Returns: TRUE if unknown options are ignored.
Since: 2.6
IMPORT_C void | g_option_context_add_main_entries | ( | GOptionContext * | context, |
const GOptionEntry * | entries, | |||
const gchar * | translation_domain | |||
) |
g_option_context_add_main_entries: : a GOptionContext : a NULL-terminated array of #GOptionEntrys : a translation domain to use for translating the <option>--help</option> output for the options in with gettext(), or NULL
A convenience function which creates a main group if it doesn't exist, adds the to it and sets the translation domain.
Since: 2.6
IMPORT_C gboolean | g_option_context_parse | ( | GOptionContext * | context, |
gint * | argc, | |||
gchar *** | argv, | |||
GError ** | error | |||
) |
g_option_context_parse: : a GOptionContext : a pointer to the number of command line arguments : a pointer to the array of command line arguments : a return location for errors
Parses the command line arguments, recognizing options which have been added to . A side-effect of calling this function is that g_set_prgname() will be called.
If the parsing is successful, any parsed arguments are removed from the array and and are updated accordingly. A '--' option is stripped from unless there are unparsed options before and after it, or some of the options after it start with '-'. In case of an error, and are left unmodified.
If automatic <option>--help</option> support is enabled (see g_option_context_set_help_enabled()), and the array contains one of the recognized help options, this function will produce help output to stdout and call <literal>exit (0)</literal>.
Note that function depends on the <link linkend="setlocale">current locale</link> for automatic character set conversion of string and filename arguments.
Return value: TRUE if the parsing was successful, FALSE if an error occurred
Since: 2.6
IMPORT_C void | g_option_context_set_translate_func | ( | GOptionContext * | context, |
GTranslateFunc | func, | |||
gpointer | data, | |||
GDestroyNotify | destroy_notify | |||
) |
g_option_context_set_translate_func: : a GOptionContext : the GTranslateFunc, or NULL : user data to pass to , or NULL : a function which gets called to free , or NULL
Sets the function which is used to translate the contexts user-visible strings, for <option>--help</option> output. If is NULL, strings are not translated.
Note that option groups have their own translation functions, this function only affects the (see g_option_context_new()), the summary (see g_option_context_set_summary()) and the description (see g_option_context_set_description()).
If you are using gettext(), you only need to set the translation domain, see g_option_context_set_translation_domain().
Since: 2.12
IMPORT_C void | g_option_context_set_translation_domain | ( | GOptionContext * | context, |
const gchar * | domain | |||
) |
g_option_context_set_translation_domain: : a GOptionContext : the domain to use
A convenience function to use gettext() for translating user-visible strings.
Since: 2.12
IMPORT_C void | g_option_context_add_group | ( | GOptionContext * | context, |
GOptionGroup * | group | |||
) |
g_option_context_add_group: : a GOptionContext : the group to add
Adds a GOptionGroup to the , so that parsing with will recognize the options in the group. Note that the group will be freed together with the context when g_option_context_free() is called, so you must not free the group yourself after adding it to a context.
Since: 2.6
IMPORT_C void | g_option_context_set_main_group | ( | GOptionContext * | context, |
GOptionGroup * | group | |||
) |
g_option_context_set_main_group: : a GOptionContext : the group to set as main group
Sets a GOptionGroup as main group of the . This has the same effect as calling g_option_context_add_group(), the only difference is that the options in the main group are treated differently when generating <option>--help</option> output.
Since: 2.6
IMPORT_C GOptionGroup * | g_option_context_get_main_group | ( | GOptionContext * | context | ) |
g_option_context_get_main_group: : a GOptionContext
Returns a pointer to the main group of .
Return value: the main group of , or NULL if doesn't have a main group. Note that group belongs to and should not be modified or freed.
Since: 2.6
IMPORT_C gchar * | g_option_context_get_help | ( | GOptionContext * | context, |
gboolean | main_help, | |||
GOptionGroup * | group | |||
) |
g_option_context_get_help: : a GOptionContext : if TRUE, only include the main group : the GOptionGroup to create help for, or NULL
Returns a formatted, translated help text for the given context. To obtain the text produced by <option>--help</option>, call <literal>g_option_context_get_help (context, TRUE, NULL)</literal>. To obtain the text produced by <option>--help-all</option>, call <literal>g_option_context_get_help (context, FALSE, NULL)</literal>. To obtain the help text for an option group, call <literal>g_option_context_get_help (context, FALSE, group)</literal>.
Returns: A newly allocated string containing the help text
Since: 2.14
IMPORT_C GOptionGroup * | g_option_group_new | ( | const gchar * | name, |
const gchar * | description, | |||
const gchar * | help_description, | |||
gpointer | user_data, | |||
GDestroyNotify | destroy | |||
) |
IMPORT_C void | g_option_group_set_parse_hooks | ( | GOptionGroup * | group, |
GOptionParseFunc | pre_parse_func, | |||
GOptionParseFunc | post_parse_func | |||
) |
g_option_group_set_parse_hooks: : a GOptionGroup : a function to call before parsing, or NULL : a function to call after parsing, or NULL
Associates two functions with which will be called from g_option_context_parse() before the first option is parsed and after the last option has been parsed, respectively.
Note that the user data to be passed to and can be specified when constructing the group with g_option_group_new().
Since: 2.6
IMPORT_C void | g_option_group_set_error_hook | ( | GOptionGroup * | group, |
GOptionErrorFunc | error_func | |||
) |
g_option_group_set_error_hook: : a GOptionGroup : a function to call when an error occurs
Associates a function with which will be called from g_option_context_parse() when an error occurs.
Note that the user data to be passed to can be specified when constructing the group with g_option_group_new().
Since: 2.6
IMPORT_C void | g_option_group_free | ( | GOptionGroup * | group | ) |
g_option_group_free: : a GOptionGroup
Frees a GOptionGroup. Note that you must <emphasis>not</emphasis> free groups which have been added to a GOptionContext.
Since: 2.6
IMPORT_C void | g_option_group_add_entries | ( | GOptionGroup * | group, |
const GOptionEntry * | entries | |||
) |
g_option_group_add_entries: : a GOptionGroup : a NULL-terminated array of #GOptionEntrys
Adds the options specified in to .
Since: 2.6
IMPORT_C void | g_option_group_set_translate_func | ( | GOptionGroup * | group, |
GTranslateFunc | func, | |||
gpointer | data, | |||
GDestroyNotify | destroy_notify | |||
) |
g_option_group_set_translate_func: : a GOptionGroup : the GTranslateFunc, or NULL : user data to pass to , or NULL : a function which gets called to free , or NULL
Sets the function which is used to translate user-visible strings, for <option>--help</option> output. Different groups can use different #GTranslateFuncs. If is NULL, strings are not translated.
If you are using gettext(), you only need to set the translation domain, see g_option_group_set_translation_domain().
Since: 2.6
IMPORT_C void | g_option_group_set_translation_domain | ( | GOptionGroup * | group, |
const gchar * | domain | |||
) |
g_option_group_set_translation_domain: : a GOptionGroup : the domain to use
A convenience function to use gettext() for translating user-visible strings.
Since: 2.6