Glib.Option

Entities

Simple Types

Array Types

Record Types

Tagged Types

Access Types

Constants

Subprograms

Generic Instantiations

Description

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.

Add_Group

procedure Add_Group (Self : Goption_Context; Group : GOption_Group)

Adds a Glib.Option.GOption_Group 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 Glib.Option.Free is called, so you must not free the group yourself after adding it to a context. Since: gtk+ 2.6

Parameters
Self
Group

the group to add

Add_Main_Entries

procedure Add_Main_Entries
   (Self               : Goption_Context;
    Entries            : GOption_Entry_Array;
    Translation_Domain : UTF8_String := "")

A convenience function which creates a main group if it doesn't exist, adds the Entries to it and sets the translation domain. Since: gtk+ 2.6

Parameters
Self
Entries

a null-terminated array of GOption_Entrys

Translation_Domain

a translation domain to use for translating the --help output for the options in Entries with gettext, or null

Free

procedure Free (Self : Goption_Context)

Frees context and all the groups which have been added to it. Please note that parsed arguments need to be freed separately (see Glib.Option.GOption_Entry). Since: gtk+ 2.6

Parameters
Self

From_Object

function From_Object (Object : System.Address) return Goption_Context
Parameters
Object
Return Value

From_Object_Free

function From_Object_Free (B : access Goption_Context'Class) return Goption_Context
Parameters
B
Return Value

From_Object_Free

function From_Object_Free (B : access GOption_Entry) return GOption_Entry

A GOptionEntry struct defines a single option. To have an effect, they must be added to a Glib.Option.GOption_Group with Glib.Option.Add_Main_Entries or g_option_group_add_entries.

Parameters
B
Return Value

From_Object_Free

function From_Object_Free (B : access GOption_Group) return GOption_Group

A GOptionGroup struct defines the options in a single group. The struct has only private fields and should not be directly accessed.

All options in a group share the same translation function. Libraries which need to parse commandline options are expected to provide a function for getting a GOptionGroup holding their options, which the application can then add to its Glib.Option.Goption_Context.

Parameters
B
Return Value

G_New

function G_New
   (Parameter_String : UTF8_String := "") return Goption_Context

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 Glib.Option.Goption_Context, 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 Glib.Option.GOption_Entry 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 Glib.Option.Set_Summary. Note that the Parameter_String is translated using the function set with Glib.Option.Set_Translate_Func, so it should normally be passed untranslated. Since: gtk+ 2.6

Parameters
Parameter_String

a string which is displayed in the first line of --help output, after the usage summary programname [OPTION...]

Return Value

a newly created Glib.Option.Goption_Context, which must be freed with Glib.Option.Free after use.

G_Option_Flag_Filename

G_Option_Flag_Filename : constant GOption_Flags := 16;

G_Option_Flag_Hidden

G_Option_Flag_Hidden : constant GOption_Flags := 1;

G_Option_Flag_In_Main

G_Option_Flag_In_Main : constant GOption_Flags := 2;

G_Option_Flag_No_Arg

G_Option_Flag_No_Arg : constant GOption_Flags := 8;

G_Option_Flag_Noalias

G_Option_Flag_Noalias : constant GOption_Flags := 64;

G_Option_Flag_None

G_Option_Flag_None : constant GOption_Flags := 0;

G_Option_Flag_Optional_Arg

G_Option_Flag_Optional_Arg : constant GOption_Flags := 32;

G_Option_Flag_Reverse

G_Option_Flag_Reverse : constant GOption_Flags := 4;

Get_Description

function Get_Description (Self : Goption_Context) return UTF8_String

Returns the description. See Glib.Option.Set_Description. Since: gtk+ 2.12

Parameters
Self
Return Value

the description

Get_Help

function Get_Help
   (Self      : Goption_Context;
    Main_Help : Boolean;
    Group     : GOption_Group) return UTF8_String

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). Since: gtk+ 2.14

Parameters
Self
Main_Help

if True, only include the main group

Group

the Glib.Option.GOption_Group to create help for, or null

Return Value

A newly allocated string containing the help text

Get_Help_Enabled

function Get_Help_Enabled (Self : Goption_Context) return Boolean

Returns whether automatic --help generation is turned on for Context. See Glib.Option.Set_Help_Enabled. Since: gtk+ 2.6

Parameters
Self
Return Value

True if automatic help generation is turned on.

Get_Ignore_Unknown_Options

function Get_Ignore_Unknown_Options
   (Self : Goption_Context) return Boolean

Returns whether unknown options are ignored or not. See Glib.Option.Set_Ignore_Unknown_Options. Since: gtk+ 2.6

Parameters
Self
Return Value

True if unknown options are ignored.

Get_Main_Group

function Get_Main_Group (Self : Goption_Context) return GOption_Group

Returns a pointer to the main group of Context. Since: gtk+ 2.6

Parameters
Self
Return Value

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.

Get_Summary

function Get_Summary (Self : Goption_Context) return UTF8_String

Returns the summary. See Glib.Option.Set_Summary. Since: gtk+ 2.12

Parameters
Self
Return Value

the summary

GOption_Arg

type GOption_Arg is (
   G_Option_Arg_None,
   G_Option_Arg_String,
   G_Option_Arg_Int,
   G_Option_Arg_Callback,
   G_Option_Arg_Filename,
   G_Option_Arg_String_Array,
   G_Option_Arg_Filename_Array,
   G_Option_Arg_Double,
   G_Option_Arg_Int64);

The Glib.Option.GOption_Arg enum values determine which type of extra argument the options expect to find. If an option expects an extra argument, it can be specified in several ways; with a short option: -x arg, with a long option: --name arg or combined in a single argument: --name=arg.

Enumeration Literal
G_Option_Arg_None
G_Option_Arg_String
G_Option_Arg_Int
G_Option_Arg_Callback
G_Option_Arg_Filename
G_Option_Arg_String_Array
G_Option_Arg_Filename_Array
G_Option_Arg_Double
G_Option_Arg_Int64

GOption_Arg_Properties

package GOption_Arg_Properties is
   new Generic_Internal_Discrete_Property (GOption_Arg);

Goption_Context

type Goption_Context is new Glib.C_Boxed with null record;

GOption_Entry

type GOption_Entry is record
   Long_Name : Gtkada.Types.Chars_Ptr;
   Short_Name : Gchar;
   Flags : GOption_Flags;
   Arg : GOption_Arg;
   Arg_Data : System.Address := System.Null_Address;
   Description : Gtkada.Types.Chars_Ptr;
   Arg_Description : Gtkada.Types.Chars_Ptr;
end record;
Record fields
Long_Name
Short_Name
Flags
Arg
Arg_Data
Description
Arg_Description

GOption_Entry_Array

type GOption_Entry_Array is array (Natural range <>) of GOption_Entry;

GOption_Error

type GOption_Error is (
   G_Option_Error_Unknown_Option,
   G_Option_Error_Bad_Value,
   G_Option_Error_Failed);

Error codes returned by option parsing.

Enumeration Literal
G_Option_Error_Unknown_Option
G_Option_Error_Bad_Value
G_Option_Error_Failed

GOption_Error_Properties

package GOption_Error_Properties is
   new Generic_Internal_Discrete_Property (GOption_Error);

GOption_Flags

type GOption_Flags is mod 2 ** Integer'Size;

Flags which modify individual options.

GOption_Flags_Properties

package GOption_Flags_Properties is
   new Generic_Internal_Discrete_Property (GOption_Flags);

GOption_Group

type GOption_Group is new Glib.C_Proxy;

A GOptionGroup struct defines the options in a single group. The struct has only private fields and should not be directly accessed.

All options in a group share the same translation function. Libraries which need to parse commandline options are expected to provide a function for getting a GOptionGroup holding their options, which the application can then add to its Glib.Option.Goption_Context.

Gtranslate_Func

type Gtranslate_Func is access function (Str : UTF8_String) return UTF8_String;

The type of functions which are used to translate user-visible strings, for <option>--help</option> output.

Parameters
Str

the untranslated string

Return Value

a translation of the string for the current locale. The returned string is owned by GLib and must not be freed.

Null_Goption_Context

Null_Goption_Context : constant Goption_Context;

Null_GOption_Entry

Null_GOption_Entry : constant GOption_Entry;

Parse

procedure Parse
  (Self         : Goption_Context;
   Argv         : access chars_ptr_array_access
   Success      : out Boolean;
   Error        : out Glib.Error.GError)

This version is suitable for use from Glib.Application.Local_Command_Line

Parameters
Self
Argv

Null-terminated

Success
Error

Parse

procedure Parse
  (Self         : Goption_Context;
   Command_Line : not null access Glib.Application.Gapplication_Command_Line_Record'Class;
   Filter       : Parse_Filter := null;
   Success      : out Boolean;
   Error        : out Glib.Error.GError)

Parses the arguments given via Command_Line, removing from the arguments list all parsed switches.

Parameters
Self
Command_Line
Filter
Success
Error

Parse_Filter

type Parse_Filter is access function (Param : String) return Boolean;

Returns True if the parameter is to be passed from Command_Line to Goption_Context

Parameters
Param
Return Value

Property_GOption_Arg

type Property_GOption_Arg is new GOption_Arg_Properties.Property;

Property_GOption_Error

type Property_GOption_Error is new GOption_Error_Properties.Property;

Property_GOption_Flags

type Property_GOption_Flags is new GOption_Flags_Properties.Property;

Set_Description

procedure Set_Description
   (Self        : Goption_Context;
    Description : UTF8_String := "")

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 Glib.Option.Set_Translate_Func). Since: gtk+ 2.12

Parameters
Self
Description

a string to be shown in --help output after the list of options, or null

Set_Help_Enabled

procedure Set_Help_Enabled
   (Self         : Goption_Context;
    Help_Enabled : Boolean)

Enables or disables automatic generation of --help output. By default, g_option_context_parse recognizes --help, -h, -?, --help-all and --help-groupname and creates suitable output to stdout. Since: gtk+ 2.6

Parameters
Self
Help_Enabled

True to enable --help, False to disable it

Set_Ignore_Unknown_Options

procedure Set_Ignore_Unknown_Options
   (Self           : Goption_Context;
    Ignore_Unknown : Boolean)

Sets whether to ignore unknown options or not. If an argument is ignored, it is left in the Argv 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: gtk+ 2.6

Parameters
Self
Ignore_Unknown

True to ignore unknown options, False to produce an error when unknown options are met

Set_Main_Group

procedure Set_Main_Group (Self : Goption_Context; Group : GOption_Group)

Sets a Glib.Option.GOption_Group as main group of the Context. This has the same effect as calling Glib.Option.Add_Group, the only difference is that the options in the main group are treated differently when generating --help output. Since: gtk+ 2.6

Parameters
Self
Group

the group to set as main group

Set_Summary

procedure Set_Summary
   (Self    : Goption_Context;
    Summary : UTF8_String := "")

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 Glib.Option.Set_Translate_Func and Glib.Option.Set_Translation_Domain). Since: gtk+ 2.12

Parameters
Self
Summary

a string to be shown in --help output before the list of options, or null

Set_Translate_Func

procedure Set_Translate_Func
   (Self           : Goption_Context;
    Func           : Gtranslate_Func;
    Destroy_Notify : Glib.G_Destroy_Notify_Address)

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 Glib.Option.G_New), the summary (see Glib.Option.Set_Summary) and the description (see Glib.Option.Set_Description). If you are using gettext, you only need to set the translation domain, see Glib.Option.Set_Translation_Domain. Since: gtk+ 2.12

Parameters
Self
Func

the Gtranslate_Func, or null

Destroy_Notify

a function which gets called to free Data, or null

Set_Translation_Domain

procedure Set_Translation_Domain
   (Self   : Goption_Context;
    Domain : UTF8_String)

A convenience function to use gettext for translating user-visible strings. Since: gtk+ 2.12

Parameters
Self
Domain

the domain to use