diff --git a/gio/gapplication.c b/gio/gapplication.c
index da9d54d..ceab8fb 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -107,6 +107,7 @@ struct _GApplicationPrivate
 
   GActionGroup      *actions;
   GMainLoop         *mainloop;
+  GOptionContext    *context;
 
   guint              inactivity_timeout_id;
   guint              inactivity_timeout;
@@ -229,6 +230,28 @@ g_application_real_local_command_line (GApplication   *application,
                                        gchar        ***arguments,
                                        int            *exit_status)
 {
+  if (application->priv->context)
+    {
+      int argc;
+      char **argv;
+      GError *error = NULL;
+
+      argv = g_strdupv (*arguments);
+      argc = g_strv_length (argv);
+      if (!g_option_context_parse (application->priv->context, &argc, &argv, &error))
+	{
+	  g_printerr (_("Run '%s --help' to see a full list of available command line options\n%s\n"),
+		      g_get_prgname (),
+		      error->message);
+	  g_error_free (error);
+	  g_strfreev (argv);
+
+	  *exit_status = 1;
+	  return TRUE;
+	}
+      g_strfreev (argv);
+    }
+
   if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
     return FALSE;
 
@@ -1224,6 +1247,16 @@ g_application_run (GApplication  *application,
   return status;
 }
 
+void
+g_application_set_option_context (GApplication   *application,
+                                  GOptionContext *context)
+{
+  g_return_if_fail (G_IS_APPLICATION (application));
+
+  application->priv->context = context;
+}
+
+
 static gboolean
 g_application_has_action (GActionGroup *action_group,
                           const gchar  *action_name)
diff --git a/gio/gapplication.h b/gio/gapplication.h
index da9a265..57bdad3 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -139,6 +139,9 @@ void                    g_application_set_flags                         (GApplic
 void                    g_application_set_action_group                  (GApplication             *application,
                                                                          GActionGroup             *action_group);
 
+void                    g_application_set_option_context                (GApplication             *application,
+                                                                         GOptionContext           *context);
+
 gboolean                g_application_get_is_registered                 (GApplication             *application);
 gboolean                g_application_get_is_remote                     (GApplication             *application);
 
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 90ea290..4871d4f 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -45,6 +45,7 @@ g_application_set_action_group
 g_application_set_application_id
 g_application_set_flags
 g_application_set_inactivity_timeout
+g_application_set_option_context
 #endif
 #endif
 
