GSList *option_groups;
GHashTable *packed_options;
gboolean options_parsed;
+
+ /* Allocated option strings, from g_application_add_main_option() */
+ GSList *option_strings;
};
enum
context = g_option_context_new (NULL);
+ /* If the application has not registered local options and it has
+ * G_APPLICATION_HANDLES_COMMAND_LINE then we have to assume that
+ * their primary instance commandline handler may want to deal with
+ * the arguments. We must therefore ignore them.
+ *
+ * We must also ignore --help in this case since some applications
+ * will try to handle this from the remote side. See #737869.
+ */
+ if (application->priv->main_options == NULL && (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE))
+ {
+ g_option_context_set_ignore_unknown_options (context, TRUE);
+ g_option_context_set_help_enabled (context, FALSE);
+ }
+
/* Add the main option group, if it exists */
if (application->priv->main_options)
{
application->priv->option_groups);
}
- /* If the application has not registered local options and it has
- * G_APPLICATION_HANDLES_COMMAND_LINE then we have to assume that
- * their primary instance commandline handler may want to deal with
- * the arguments. We must therefore ignore them.
- */
- if (application->priv->main_options == NULL && (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE))
- g_option_context_set_ignore_unknown_options (context, TRUE);
-
/* In the case that we are not explicitly marked as a service or a
* launcher then we want to add the "--gapplication-service" option to
* allow the process to be made into a service.
}
/**
+ * g_application_add_main_option:
+ * @application: the #GApplication
+ * @long_name: the long name of an option used to specify it in a commandline
+ * @short_name: the short name of an option
+ * @flags: flags from #GOptionFlags
+ * @arg: the type of the option, as a #GOptionArg
+ * @description: the description for the option in `--help` output
+ * @arg_description: (nullable): the placeholder to use for the extra argument
+ * parsed by the option in `--help` output
+ *
+ * Add an option to be handled by @application.
+ *
+ * Calling this function is the equivalent of calling
+ * g_application_add_main_option_entries() with a single #GOptionEntry
+ * that has its arg_data member set to %NULL.
+ *
+ * The parsed arguments will be packed into a #GVariantDict which
+ * is passed to #GApplication::handle-local-options. If
+ * %G_APPLICATION_HANDLES_COMMAND_LINE is set, then it will also
+ * be sent to the primary instance. See
+ * g_application_add_main_option_entries() for more details.
+ *
+ * See #GOptionEntry for more documentation of the arguments.
+ *
+ * Since: 2.42
+ **/
+void
+g_application_add_main_option (GApplication *application,
+ const char *long_name,
+ char short_name,
+ GOptionFlags flags,
+ GOptionArg arg,
+ const char *description,
+ const char *arg_description)
+{
+ gchar *dup_string;
+ GOptionEntry my_entry[2] = {
+ { NULL, short_name, flags, arg, NULL, NULL, NULL },
+ { NULL }
+ };
+
+ g_return_if_fail (G_IS_APPLICATION (application));
+ g_return_if_fail (long_name != NULL);
+ g_return_if_fail (description != NULL);
+
+ my_entry[0].long_name = dup_string = g_strdup (long_name);
+ application->priv->option_strings = g_slist_prepend (application->priv->option_strings, dup_string);
+
+ my_entry[0].description = dup_string = g_strdup (description);
+ application->priv->option_strings = g_slist_prepend (application->priv->option_strings, dup_string);
+
+ my_entry[0].arg_description = dup_string = g_strdup (arg_description);
+ application->priv->option_strings = g_slist_prepend (application->priv->option_strings, dup_string);
+
+ g_application_add_main_option_entries (application, my_entry);
+}
+
+/**
* g_application_add_option_group:
* @application: the #GApplication
* @group: a #GOptionGroup
if (application->priv->main_options)
g_option_group_free (application->priv->main_options);
if (application->priv->packed_options)
- g_hash_table_unref (application->priv->packed_options);
-
+ {
+ g_slist_free_full (application->priv->option_strings, g_free);
+ g_hash_table_unref (application->priv->packed_options);
+ }
if (application->priv->impl)
g_application_impl_destroy (application->priv->impl);
g_free (application->priv->id);
if (application->priv->notifications)
g_object_unref (application->priv->notifications);
+ g_free (application->priv->resource_path);
+
G_OBJECT_CLASS (g_application_parent_class)
->finalize (object);
}
* decide to perform certain actions, including direct local handling
* (which may be useful for options like --version).
*
- * If the options have been "handled" then a non-negative value should
- * be returned. In this case, the return value is the exit status: 0
- * for success and a positive value for failure. -1 means to continue
- * normal processing.
- *
* In the event that the application is marked
* %G_APPLICATION_HANDLES_COMMAND_LINE the "normal processing" will
* send the @option dictionary to the primary instance where it can be
* capabilities than what is provided here, but this should not
* normally be required.
*
+ * Returns: an exit code. If you have handled your options and want
+ * to exit the process, return a non-negative option, 0 for success,
+ * and a positive value for failure. To continue, return -1 to let
+ * the default option processing continue.
+ *
* Since: 2.40
**/
g_application_signals[SIGNAL_HANDLE_LOCAL_OPTIONS] =
*/
void
g_application_set_resource_base_path (GApplication *application,
- const gchar *resource_path)
+ const gchar *resource_path)
{
g_return_if_fail (G_IS_APPLICATION (application));
g_return_if_fail (resource_path == NULL || g_str_has_prefix (resource_path, "/"));