summaryrefslogtreecommitdiff
path: root/src/programs/pkaction.c
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2013-04-20 00:20:21 +0200
committerMiloslav Trmač <mitr@redhat.com>2013-05-13 17:41:29 +0200
commite8e18d180888435dc26e8e4e461689f0efa91f04 (patch)
tree27ad2a6e81faade95d3ad06503e5e429fb6cb9e3 /src/programs/pkaction.c
parent8d8a6213c6a8882dc1b51a2030713914c75d6fb9 (diff)
downloadpolkit-e8e18d180888435dc26e8e4e461689f0efa91f04.tar.gz
Don't spawn man for --help
Convert pkaction and pkttyagent to use GOptionContext. Don't convert pkcheck and only add --help output text because its non-standard --details(which requires two arguments) can't be implemented using GOptionContext. Don't touch pkexec, in a (futile?) attempt to minimize the amount of complex code running before authentication. This leaves the option processing lax as it was (e.g. accepting contradicting options, ignoring non-option arguments), and should only affect the handling of --help and behavior when invalid arguments are detected. https://bugs.freedesktop.org/show_bug.cgi?id=29936
Diffstat (limited to 'src/programs/pkaction.c')
-rw-r--r--src/programs/pkaction.c91
1 files changed, 34 insertions, 57 deletions
diff --git a/src/programs/pkaction.c b/src/programs/pkaction.c
index 00b2c57..f2969cc 100644
--- a/src/programs/pkaction.c
+++ b/src/programs/pkaction.c
@@ -24,26 +24,10 @@
#endif
#include <stdio.h>
+#include <glib/gi18n.h>
#include <polkit/polkit.h>
static void
-usage (int argc, char *argv[])
-{
- GError *error;
-
- error = NULL;
- if (!g_spawn_command_line_sync ("man pkaction",
- NULL,
- NULL,
- NULL,
- &error))
- {
- g_printerr ("Cannot show manual page: %s\n", error->message);
- g_error_free (error);
- }
-}
-
-static void
print_action (PolkitActionDescription *action,
gboolean opt_verbose)
{
@@ -104,68 +88,59 @@ action_desc_compare_by_action_id_func (PolkitActionDescription *a,
int
main (int argc, char *argv[])
{
- guint n;
guint ret;
- gchar *action_id;
- gboolean opt_show_help;
+ gchar *opt_action_id;
gboolean opt_show_version;
gboolean opt_verbose;
+ GOptionEntry options[] =
+ {
+ {
+ "action-id", 'a', 0, G_OPTION_ARG_STRING, &opt_action_id,
+ N_("Only output information about ACTION"), N_("ACTION")
+ },
+ {
+ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose,
+ N_("Output detailed action information"), NULL
+ },
+ {
+ "version", 0, 0, G_OPTION_ARG_NONE, &opt_show_version,
+ N_("Show version"), NULL
+ },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+ GOptionContext *context;
PolkitAuthority *authority;
GList *l;
GList *actions;
GError *error;
- action_id = NULL;
+ opt_action_id = NULL;
+ context = NULL;
authority = NULL;
actions = NULL;
ret = 1;
g_type_init ();
- opt_show_help = FALSE;
opt_show_version = FALSE;
opt_verbose = FALSE;
- for (n = 1; n < (guint) argc; n++)
- {
- if (g_strcmp0 (argv[n], "--help") == 0)
- {
- opt_show_help = TRUE;
- }
- else if (g_strcmp0 (argv[n], "--version") == 0)
- {
- opt_show_version = TRUE;
- }
- else if (g_strcmp0 (argv[n], "--action-id") == 0 || g_strcmp0 (argv[n], "-a") == 0)
- {
- n++;
- if (n >= (guint) argc)
- {
- usage (argc, argv);
- goto out;
- }
-
- action_id = g_strdup (argv[n]);
- }
- else if (g_strcmp0 (argv[n], "--verbose") == 0 || g_strcmp0 (argv[n], "-v") == 0)
- {
- opt_verbose = TRUE;
- }
- }
- if (opt_show_help)
+ error = NULL;
+ context = g_option_context_new (N_("[--action-id ACTION]"));
+ g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
+ if (!g_option_context_parse (context, &argc, &argv, &error))
{
- usage (argc, argv);
- ret = 0;
+ g_printerr ("%s: %s\n", g_get_prgname (), error->message);
+ g_error_free (error);
goto out;
}
- else if (opt_show_version)
+ if (opt_show_version)
{
g_print ("pkaction version %s\n", PACKAGE_VERSION);
ret = 0;
goto out;
}
- error = NULL;
authority = polkit_authority_get_sync (NULL /* GCancellable* */, &error);
if (authority == NULL)
{
@@ -185,7 +160,7 @@ main (int argc, char *argv[])
goto out;
}
- if (action_id != NULL)
+ if (opt_action_id != NULL)
{
for (l = actions; l != NULL; l = l->next)
{
@@ -194,7 +169,7 @@ main (int argc, char *argv[])
id = polkit_action_description_get_action_id (action);
- if (g_strcmp0 (id, action_id) == 0)
+ if (g_strcmp0 (id, opt_action_id) == 0)
{
print_action (action, opt_verbose);
break;
@@ -203,7 +178,7 @@ main (int argc, char *argv[])
if (l == NULL)
{
- g_printerr ("No action with action id %s\n", action_id);
+ g_printerr ("No action with action id %s\n", opt_action_id);
goto out;
}
}
@@ -224,11 +199,13 @@ main (int argc, char *argv[])
g_list_foreach (actions, (GFunc) g_object_unref, NULL);
g_list_free (actions);
- g_free (action_id);
+ g_free (opt_action_id);
if (authority != NULL)
g_object_unref (authority);
+ g_option_context_free (context);
+
return ret;
}