add_main_option_entries


Description:

[ Version ( since = "2.40" ) ]
public void add_main_option_entries (OptionEntry[] entries)

Adds main option entries to be handled by this.

This function is comparable to add_main_entries.

After the commandline arguments are parsed, the handle_local_options signal will be emitted. At this point, the application can inspect the values pointed to by arg_data in the given OptionEntrys.

Unlike OptionContext, Application supports giving a null arg_data for a non-callback OptionEntry. This results in the argument in question being packed into a VariantDict which is also passed to handle_local_options, where it can be inspected and modified. If g_application_handles_command_line is set, then the resulting dictionary is sent to the primary instance, where get_options_dict will return it. As it has been passed outside the process at this point, the types of all values in the options dict must be checked before being used. This "packing" is done according to the type of the argument -- booleans for normal flags, strings for strings, bytestrings for filenames, etc. The packing only occurs if the flag is given (ie: we do not pack a "false" Variant in the case that a flag is missing).

In general, it is recommended that all commandline arguments are parsed locally. The options dictionary should then be used to transmit the result of the parsing to the primary instance, where lookup can be used. For local options, it is possible to either use arg_data in the usual way, or to consult (and potentially remove) the option from the options dictionary.

This function is new in GLib 2.40. Before then, the only real choice was to send all of the commandline arguments (options and all) to the primary instance for handling. Application ignored them completely on the local side. Calling this function "opts in" to the new behaviour, and in particular, means that unrecognised options will be treated as errors. Unrecognised options have never been ignored when g_application_handles_command_line is unset.

If handle_local_options needs to see the list of filenames, then the use of g_option_remaining is recommended. If arg_data is null then g_option_remaining can be used as a key into the options dictionary. If you do use g_option_remaining then you need to handle these arguments for yourself because once they are consumed, they will no longer be visible to the default handling (which treats them as filenames to be opened).

It is important to use the proper GVariant format when retrieving the options with lookup: - for g_option_arg_none, use `b` - for g_option_arg_string, use `&s` - for g_option_arg_int, use `i` - for g_option_arg_int64, use `x` - for g_option_arg_double, use `d` - for g_option_arg_filename, use `^&ay` - for g_option_arg_string_array, use `^a&s` - for g_option_arg_filename_array, use `^a&ay`

Parameters:

this

a Application

entries

the main options for the application