OptionGroup

Description The GOption commandline parser is intended to be a simpler replacement for the popt library. It supports short and long commandline options, as shown in the following example: testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2 The example demonstrates a number of features of the GOption commandline parser Options can be single letters, prefixed by a single dash. Multiple short options can be grouped behind a single dash. Long options are prefixed by two consecutive dashes. Options can have an extra argument, which can be a number, a string or a filename. For long options, the extra argument can be appended with an equals sign after the option name, which is useful if the extra argument starts with a dash, which would otherwise cause it to be interpreted as another option. Non-option arguments are returned to the application as rest arguments. An argument consisting solely of two dashes turns off further parsing, any remaining arguments (even those starting with a dash) are returned to the application as rest arguments. Another important feature of GOption is that it can automatically generate nicely formatted help output. Unless it is explicitly turned off with g_option_context_set_help_enabled(), GOption will recognize the --help, -?, --help-all and --help-groupname options (where groupname is the name of a GOptionGroup) and write a text similar to the one shown in the following example to stdout. GOption groups options in GOptionGroups, which makes it easy to incorporate options from multiple sources. The intended use for this is to let applications collect option groups from the libraries it uses, add them to their GOptionContext, and parse all options by a single call to g_option_context_parse(). See gtk_get_option_group() for an example. If an option is declared to be of type string or filename, GOption takes care of converting it to the right encoding; strings are returned in UTF-8, filenames are returned in the GLib filename encoding. Note that this only works if setlocale() has been called before g_option_context_parse(). Here is a complete example of setting up GOption to parse the example commandline above and produce the example help output.

Constructors

this
this(GOptionGroup* gOptionGroup)

Sets our main struct and passes it to the parent class

this
this(string name, string description, string helpDescription, void* userData, GDestroyNotify destroy)

Creates a new GOptionGroup. Since 2.6

Members

Functions

addEntries
void addEntries(GOptionEntry* entries)

Adds the options specified in entries to group. Since 2.6

free
void free()

Frees a GOptionGroup. Note that you must not free groups which have been added to a GOptionContext. Since 2.6

getOptionGroupStruct
GOptionGroup* getOptionGroupStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getStruct
void* getStruct()

the main Gtk struct as a void*

setErrorHook
void setErrorHook(GOptionErrorFunc errorFunc)

Associates a function with group which will be called from g_option_context_parse() when an error occurs. Note that the user data to be passed to error_func can be specified when constructing the group with g_option_group_new(). Since 2.6

setParseHooks
void setParseHooks(GOptionParseFunc preParseFunc, GOptionParseFunc postParseFunc)

Associates two functions with group 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 pre_parse_func and post_parse_func can be specified when constructing the group with g_option_group_new(). Since 2.6

setTranslateFunc
void setTranslateFunc(GTranslateFunc func, void* data, GDestroyNotify destroyNotify)

Sets the function which is used to translate user-visible strings, for --help output. Different groups can use different GTranslateFuncs. If func 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

setTranslationDomain
void setTranslationDomain(string domain)

A convenience function to use gettext() for translating user-visible strings. Since 2.6

Variables

gOptionGroup
GOptionGroup* gOptionGroup;

the main Gtk struct

Meta