[ostree] ostadmin: fix command line handling in the builtins
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] ostadmin: fix command line handling in the builtins
- Date: Sat, 18 Aug 2012 17:23:54 +0000 (UTC)
commit edf69d6283cf4fc2eab7a471b71a89a5ed5e2b3f
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Mon Aug 13 23:45:03 2012 +0200
ostadmin: fix command line handling in the builtins
Common code was duplicating the command name and not shifting
arguments properly, which thus required the builtins to be aware
of it, instead of being treated like subcommands.
src/ostadmin/ot-admin-builtin-deploy.c | 8 ++++----
src/ostadmin/ot-admin-main.c | 19 ++++++++++---------
2 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/src/ostadmin/ot-admin-builtin-deploy.c b/src/ostadmin/ot-admin-builtin-deploy.c
index e35eeec..4665889 100644
--- a/src/ostadmin/ot-admin-builtin-deploy.c
+++ b/src/ostadmin/ot-admin-builtin-deploy.c
@@ -368,15 +368,15 @@ ot_admin_builtin_deploy (int argc, char **argv, GError **error)
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (argc < 3)
+ if (argc < 2)
{
ot_util_usage_error (context, "NAME must be specified", error);
goto out;
}
- deploy_target = argv[2];
- if (argc > 3)
- revision = argv[3];
+ deploy_target = argv[1];
+ if (argc > 2)
+ revision = argv[2];
if (!do_checkout (self, deploy_target, revision, cancellable, error))
goto out;
diff --git a/src/ostadmin/ot-admin-main.c b/src/ostadmin/ot-admin-main.c
index 52b26f6..6052d90 100644
--- a/src/ostadmin/ot-admin-main.c
+++ b/src/ostadmin/ot-admin-main.c
@@ -61,14 +61,15 @@ prep_builtin_argv (const char *builtin,
{
int i;
char **cmd_argv;
-
- cmd_argv = g_new0 (char *, argc + 2);
-
- cmd_argv[0] = (char*)builtin;
- for (i = 0; i < argc; i++)
- cmd_argv[i+1] = argv[i];
- cmd_argv[i+1] = NULL;
- *out_argc = argc+1;
+
+ /* Should be argc - 1 + 1, to account for
+ the first argument (removed) and for NULL pointer */
+ cmd_argv = g_new0 (char *, argc);
+
+ for (i = 0; i < argc-1; i++)
+ cmd_argv[i] = argv[i+1];
+ cmd_argv[i] = NULL;
+ *out_argc = argc-1;
*out_argv = cmd_argv;
}
@@ -123,7 +124,7 @@ ot_admin_main (int argc,
goto out;
}
- prep_builtin_argv (cmd, argc-1, argv+1, &cmd_argc, &cmd_argv);
+ prep_builtin_argv (cmd, argc, argv, &cmd_argc, &cmd_argv);
if (!builtin->fn (cmd_argc, cmd_argv, &error))
goto out;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]