Re: Support for non-builtin commands



On 08/10/2012 06:53 PM, Colin Walters wrote:
> On Fri, 2012-08-10 at 16:01 +0200, Stef Walter wrote:
>> So while waiting for ostree-pull (it's still going :), I put together
>> this patch so that you can run 'ostree pull' instead of 'ostree-pull'.
> 
> Oh, that is clever code!  Push please!

Done.

> However the (minor) downside of this is that it doesn't show up when I
> just type "ostree" to list commands, but git doesn't have that either.
> Maybe we could just manually add it to the help?

Something like the attached patch? Although the help produced when you
type 'ostree pull' isn't very helpful. Probably needs to show usage per
command instead anyway.

Cheers,

Stef

>From 46d715ccff2f12620e7ed6fe5aded64e60a3a1d3 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw gnome org>
Date: Fri, 10 Aug 2012 23:12:01 +0200
Subject: [PATCH] Include pull and other external commands in usage output

---
 src/ostree/main.c        |  9 ++++++---
 src/ostree/ostree-pull.c |  4 ++--
 src/ostree/ot-main.c     | 40 +++++++++++++++++++++-------------------
 src/ostree/ot-main.h     |  8 ++++----
 4 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/src/ostree/main.c b/src/ostree/main.c
index 5d7260f..09620d2 100644
--- a/src/ostree/main.c
+++ b/src/ostree/main.c
@@ -30,7 +30,7 @@
 #include "ot-main.h"
 #include "ot-builtins.h"
 
-static OstreeBuiltin builtins[] = {
+static OstreeCommand commands[] = {
   { "cat", ostree_builtin_cat, 0 },
   { "config", ostree_builtin_config, 0 },
   { "checkout", ostree_builtin_checkout, 0 },
@@ -44,10 +44,13 @@ static OstreeBuiltin builtins[] = {
   { "prune", ostree_builtin_prune, 0 },
   { "fsck", ostree_builtin_fsck, 0 },
   { "pack", ostree_builtin_pack, 0 },
+  { "pull", NULL, 0 },
   { "remote", ostree_builtin_remote, 0 },
   { "rev-parse", ostree_builtin_rev_parse, 0 },
   { "remote", ostree_builtin_remote, 0 },
+  { "run-triggers", NULL, 0 },
   { "show", ostree_builtin_show, 0 },
+  { "switch-root", NULL, 0 },
   { "unpack", ostree_builtin_unpack, 0 },
   { "write-refs", ostree_builtin_write_refs, 0 },
   { NULL }
@@ -94,7 +97,7 @@ main (int    argc,
   GError *error = NULL;
   int ret;
 
-  ret = ostree_run (argc, argv, builtins, &error);
+  ret = ostree_run (argc, argv, commands, &error);
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
     {
       g_clear_error (&error);
@@ -102,7 +105,7 @@ main (int    argc,
     }
 
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
-    ostree_usage (argv, builtins, TRUE);
+    ostree_usage (argv, commands, TRUE);
 
   if (error != NULL)
     {
diff --git a/src/ostree/ostree-pull.c b/src/ostree/ostree-pull.c
index 2d745f1..fa5d55c 100644
--- a/src/ostree/ostree-pull.c
+++ b/src/ostree/ostree-pull.c
@@ -1672,7 +1672,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   return ret;
 }
 
-static OstreeBuiltin builtins[] = {
+static OstreeCommand commands[] = {
   { "pull", ostree_builtin_pull, 0 },
   { NULL }
 };
@@ -1681,5 +1681,5 @@ int
 main (int    argc,
       char **argv)
 {
-  return ostree_main (argc, argv, builtins);
+  return ostree_main (argc, argv, commands);
 }
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
index 2f64fc5..90f3209 100644
--- a/src/ostree/ot-main.c
+++ b/src/ostree/ot-main.c
@@ -30,9 +30,11 @@
 #include "otutil.h"
 
 int
-ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
+ostree_usage (char **argv,
+              OstreeCommand *commands,
+              gboolean is_error)
 {
-  OstreeBuiltin *builtin = builtins;
+  OstreeCommand *command = commands;
   void (*print_func) (const gchar *format, ...);
 
   if (is_error)
@@ -44,10 +46,10 @@ ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
               argv[0]);
   print_func ("Builtin commands:\n");
 
-  while (builtin->name)
+  while (command->name)
     {
-      print_func ("  %s\n", builtin->name);
-      builtin++;
+      print_func ("  %s\n", command->name);
+      command++;
     }
   return (is_error ? 1 : 0);
 }
@@ -75,10 +77,10 @@ prep_builtin_argv (const char *builtin,
 int
 ostree_run (int    argc,
             char **argv,
-            OstreeBuiltin  *builtins,
+            OstreeCommand *commands,
             GError **res_error)
 {
-  OstreeBuiltin *builtin;
+  OstreeCommand *command;
   GError *error = NULL;
   int cmd_argc;
   char **cmd_argv = NULL;
@@ -99,7 +101,7 @@ ostree_run (int    argc,
   g_set_prgname (argv[0]);
 
   if (argc < 2)
-    return ostree_usage (argv, builtins, 1);
+    return ostree_usage (argv, commands, TRUE);
 
   am_root = getuid () == 0;
   have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
@@ -140,32 +142,32 @@ ostree_run (int    argc,
       cmd = argv[arg_off-1];
     }
 
-  builtin = builtins;
-  while (builtin->name)
+  command = commands;
+  while (command->name)
     {
-      if (g_strcmp0 (cmd, builtin->name) == 0)
+      if (g_strcmp0 (cmd, command->name) == 0)
         break;
-      builtin++;
+      command++;
     }
 
-  if (!builtin->name)
+  if (!command->fn)
     {
       ot_lfree char *msg = g_strdup_printf ("Unknown command '%s'", cmd);
       g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, msg);
       goto out;
     }
 
-  if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
+  if (repo == NULL && !(command->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
     {
       g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "Command requires a --repo argument");
-      ostree_usage (argv, builtins, TRUE);
+      ostree_usage (argv, commands, TRUE);
       goto out;
     }
   
   prep_builtin_argv (cmd, argc-arg_off, argv+arg_off, &cmd_argc, &cmd_argv);
 
-  if (!builtin->fn (cmd_argc, cmd_argv, repo_file, &error))
+  if (!command->fn (cmd_argc, cmd_argv, repo_file, &error))
     goto out;
 
  out:
@@ -182,15 +184,15 @@ ostree_run (int    argc,
 int
 ostree_main (int    argc,
              char **argv,
-             OstreeBuiltin  *builtins)
+             OstreeCommand *commands)
 {
   GError *error = NULL;
   int ret;
 
-  ret = ostree_run (argc, argv, builtins, &error);
+  ret = ostree_run (argc, argv, commands, &error);
 
   if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
-    ostree_usage (argv, builtins, TRUE);
+    ostree_usage (argv, commands, TRUE);
 
   if (error)
     {
diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h
index 7712db1..4deb086 100644
--- a/src/ostree/ot-main.h
+++ b/src/ostree/ot-main.h
@@ -31,10 +31,10 @@ typedef struct {
   const char *name;
   gboolean (*fn) (int argc, char **argv, GFile *repo_path, GError **error);
   int flags; /* OstreeBuiltinFlags */
-} OstreeBuiltin;
+} OstreeCommand;
 
-int ostree_main (int    argc, char **argv, OstreeBuiltin  *builtins);
+int ostree_main (int    argc, char **argv, OstreeCommand  *commands);
 
-int ostree_run (int    argc, char **argv, OstreeBuiltin  *builtins, GError **error);
+int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error);
 
-int ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error);
+int ostree_usage (char **argv, OstreeCommand *commands, gboolean is_error);
-- 
1.7.11.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]