W Wrapl, The Programming Language





Nil : T


New(parameter_string @ Std.String.T) : Gtk.Glib.GOptionContext.T

Creates a new option context.

The parameter_string can serve multiple purposes. It can be used to add descriptions for "rest" arguments, which are not parsed by the T, 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 arg_description of the corresponding Gtk.Glib.GOptionEntry.T 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 SetSummary.

Note that the parameter_string is translated using the function set with SetTranslateFunc, so it should normally be passed untranslated.

parameter_string a string which is displayed in the first line of --help output, after the usage summary programname [OPTION...]
Returns a newly created T, which must be freed with Free after use.


:"="(_ @ T, _ @ T)

:AddGroup(self @ T, group @ Gtk.Glib.GOptionGroup.T) : Std.Object.T

Adds a Gtk.Glib.GOptionGroup.T to the context, so that parsing with context will recognize the options in the group. Note that the group will be freed together with the context when Free is called, so you must not free the group yourself after adding it to a context.

context a T
group the group to add

:AddMainEntries(self @ T, entries @ Gtk.Glib.GOptionEntry.T, translation_domain @ Std.String.T) : Std.Object.T

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

context a T
entries a NULL-terminated array of Gtk.Glib.GOptionEntry.Ts
translation_domain a translation domain to use for translating the --help output for the options in entries with gettext(), or NULL

:Free(self @ T) : Std.Object.T

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

Please note that parsed arguments need to be freed separately (see Gtk.Glib.GOptionEntry.T).

context a T

:GetDescription(self @ T) : Std.String.T

Returns the description. See SetDescription.

context a T
Returns the description

:GetHelp(self @ T, main_help @ Std.Symbol.T, group @ Gtk.Glib.GOptionGroup.T) : Std.String.T

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).

context a T
main_help if TRUE, only include the main group
group the Gtk.Glib.GOptionGroup.T to create help for, or NULL
Returns A newly allocated string containing the help text

:GetHelpEnabled(self @ T) : Std.Symbol.T

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

context a T
Returns TRUE if automatic help generation is turned on.

:GetIgnoreUnknownOptions(self @ T) : Std.Symbol.T

Returns whether unknown options are ignored or not. See SetIgnoreUnknownOptions.

context a T
Returns TRUE if unknown options are ignored.

:GetMainGroup(self @ T) : Gtk.Glib.GOptionGroup.T

Returns a pointer to the main group of context.

context a T
Returns the main group of context, or NULL if context doesn't have a main group. Note that group belongs to context and should not be modified or freed.

:GetSummary(self @ T) : Std.String.T

Returns the summary. See SetSummary.

context a T
Returns the summary

:Parse(self @ T, argc @ Std.Object.T, argv @ Std.Object.T, error @ Std.Object.T) : Std.Symbol.T

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

If the parsing is successful, any parsed arguments are removed from the array and argc and argv are updated accordingly. A '--' option is stripped from argv unless there are unparsed options before and after it, or some of the options after it start with '-'. In case of an error, argc and argv are left unmodified.

If automatic --help support is enabled (see SetHelpEnabled), and the argv array contains one of the recognized help options, this function will produce help output to stdout and call exit (0).

Note that function depends on the current locale for automatic character set conversion of string and filename arguments.

context a T
argc a pointer to the number of command line arguments. [inout][allow-none]
argv a pointer to the array of command line arguments. [inout][array length=argc][allow-none]
error a return location for errors
Returns TRUE if the parsing was successful, FALSE if an error occurred

:SetDescription(self @ T, description @ Std.String.T) : Std.Object.T

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

Note that the summary is translated (see SetTranslateFunc).

context a T
description a string to be shown in --help output after the list of options, or NULL

:SetHelpEnabled(self @ T, help_enabled @ Std.Symbol.T) : Std.Object.T

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

context a T
help_enabled TRUE to enable --help, FALSE to disable it

:SetIgnoreUnknownOptions(self @ T, ignore_unknown @ Std.Symbol.T) : Std.Object.T

Sets whether to ignore unknown options or not. If an argument is ignored, it is left in the argv array after parsing. By default, 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.

context a T
ignore_unknown TRUE to ignore unknown options, FALSE to produce an error when unknown options are met

:SetMainGroup(self @ T, group @ Gtk.Glib.GOptionGroup.T) : Std.Object.T

Sets a Gtk.Glib.GOptionGroup.T as main group of the context. This has the same effect as calling AddGroup, the only difference is that the options in the main group are treated differently when generating --help output.

context a T
group the group to set as main group

:SetSummary(self @ T, summary @ Std.String.T) : Std.Object.T

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

Note that the summary is translated (see SetTranslateFunc and SetTranslationDomain).

context a T
summary a string to be shown in --help output before the list of options, or NULL

:SetTranslateFunc(self @ T, func @ Std.Object.T, data @ Std.Address.T, destroy_notify @ Std.Function.T) : Std.Object.T

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

Note that option groups have their own translation functions, this function only affects the parameter_string (see g_option_context_new()), the summary (see SetSummary) and the description (see SetDescription).

If you are using gettext(), you only need to set the translation domain, see SetTranslationDomain.

context a T
func the GTranslateFunc, or NULL
data user data to pass to func, or NULL
destroy_notify a function which gets called to free data, or NULL

:SetTranslationDomain(self @ T, domain @ Std.String.T) : Std.Object.T

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

context a T
domain the domain to use

:"~="(_ @ T, _ @ T)