OptionContext

A GOptionContext struct defines which options are accepted by the commandline option parser. The struct has only private fields and should not be directly accessed.

Constructors

this
this(GOptionContext* gOptionContext, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(string parameterString)

Creates a new option context.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

addGroup
void addGroup(OptionGroup group)

Adds a glib.OptionGroup to the context, so that parsing with context will recognize the options in the group. Note that this will take ownership of the group and thus the group should not be freed.

addMainEntries
void addMainEntries(GOptionEntry[] entries, string translationDomain)

A convenience function which creates a main group if it doesn't exist, adds the entries to it and sets the translation domain.

free
void free()

Frees context and all the groups which have been added to it.

getDescription
string getDescription()

Returns the description. See OptionContext.setDescription.

getHelp
string getHelp(bool mainHelp, OptionGroup group)

Returns a formatted, translated help text for the given context. To obtain the text produced by --help, call g_option_context_get_help (context, TRUE, NULL). To obtain the text produced by --help-all, call g_option_context_get_help (context, FALSE, NULL). To obtain the help text for an option group, call g_option_context_get_help (context, FALSE, group).

getHelpEnabled
bool getHelpEnabled()

Returns whether automatic --help generation is turned on for context. See OptionContext.setHelpEnabled.

getIgnoreUnknownOptions
bool getIgnoreUnknownOptions()

Returns whether unknown options are ignored or not. See OptionContext.setIgnoreUnknownOptions.

getMainGroup
OptionGroup getMainGroup()

Returns a pointer to the main group of context.

getOptionContextStruct
GOptionContext* getOptionContextStruct(bool transferOwnership)

Get the main Gtk struct

getStrictPosix
bool getStrictPosix()

Returns whether strict POSIX code is enabled.

getStruct
void* getStruct()

the main Gtk struct as a void*

getSummary
string getSummary()

Returns the summary. See OptionContext.setSummary.

parse
bool parse(string[] argv)

Parses the command line arguments, recognizing options which have been added to context. A side-effect of calling this function is that g_set_prgname() will be called.

parseStrv
bool parseStrv(string[] arguments)

Parses the command line arguments.

setDescription
void setDescription(string description)

Adds a string to be displayed in --help output after the list of options. This text often includes a bug reporting address.

setHelpEnabled
void setHelpEnabled(bool helpEnabled)

Enables or disables automatic generation of --help output. By default, OptionContext.parse recognizes --help, -h, -?, --help-all and --help-groupname and creates suitable output to stdout.

setIgnoreUnknownOptions
void setIgnoreUnknownOptions(bool ignoreUnknown)

Sets whether to ignore unknown options or not. If an argument is ignored, it is left in the argv array after parsing. By default, OptionContext.parse treats unknown options as error.

setMainGroup
void setMainGroup(OptionGroup group)

Sets a glib.OptionGroup as main group of the context. This has the same effect as calling OptionContext.addGroup, the only difference is that the options in the main group are treated differently when generating --help output.

setStrictPosix
void setStrictPosix(bool strictPosix)

Sets strict POSIX mode.

setSummary
void setSummary(string summary)

Adds a string to be displayed in --help output before the list of options. This is typically a summary of the program functionality.

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

Sets the function which is used to translate the contexts user-visible strings, for --help output. If func is NULL, strings are not translated.

setTranslationDomain
void setTranslationDomain(string domain)

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

Static functions

optionErrorQuark
GQuark optionErrorQuark()

Variables

gOptionContext
GOptionContext* gOptionContext;

the main Gtk struct