]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
allow name for VSH_OT_ARGV options
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 7 Jun 2011 09:11:08 +0000 (17:11 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 14 Jun 2011 17:05:09 +0000 (11:05 -0600)
A name will improve the usege, example

# virsh help echo
  NAME
    echo - echo arguments

  SYNOPSIS
    echo [--shell] [--xml] [<string>]...

  DESCRIPTION
    Echo back arguments, possibly with quoting.

  OPTIONS
    --shell          escape for shell use
    --xml            escape for XML use
    <string>         arguments to echo

"[<string>]..." is added to SYNOPSIS.
"<string>         arguments to echo" is added to OPTIONS.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
tools/virsh.c

index f4013de3a1adf4c6f3736f9b127d861694ea0981..d2f4020ee2a75a89a477de75af1a9928f36ab93e 100644 (file)
@@ -126,7 +126,7 @@ typedef enum {
     VSH_OT_STRING,   /* optional string option */
     VSH_OT_INT,      /* optional or mandatory int option */
     VSH_OT_DATA,     /* string data (as non-option) */
-    VSH_OT_ARGV      /* remaining arguments, opt->name should be "" */
+    VSH_OT_ARGV      /* remaining arguments */
 } vshCmdOptType;
 
 /*
@@ -10426,7 +10426,7 @@ static const vshCmdInfo info_echo[] = {
 static const vshCmdOptDef opts_echo[] = {
     {"shell", VSH_OT_BOOL, 0, N_("escape for shell use")},
     {"xml", VSH_OT_BOOL, 0, N_("escape for XML use")},
-    {"", VSH_OT_ARGV, 0, N_("arguments to echo")},
+    {"string", VSH_OT_ARGV, 0, N_("arguments to echo")},
     {NULL, 0, 0, NULL}
 };
 
@@ -11479,6 +11479,11 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
                 vshError(ctl, _("option --%s already seen"), name);
                 return NULL;
             }
+            if (opt->type == VSH_OT_ARGV) {
+                vshError(ctl, _("variable argument <%s> "
+                         "should not be used with --<%s>"), name, name);
+                return NULL;
+            }
             *opts_seen |= 1 << i;
             return opt;
         }
@@ -11527,7 +11532,7 @@ vshCommandCheckOpts(vshControl *ctl, const vshCmd *cmd, uint32_t opts_required,
             const vshCmdOptDef *opt = &def->opts[i];
 
             vshError(ctl,
-                     opt->type == VSH_OT_DATA ?
+                     opt->type == VSH_OT_DATA || opt->type == VSH_OT_ARGV ?
                      _("command '%s' requires <%s> option") :
                      _("command '%s' requires --%s option"),
                      def->name, opt->name);
@@ -11635,7 +11640,8 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
                     break;
                 case VSH_OT_ARGV:
                     /* xgettext:c-format */
-                    fmt = _("[<string>]...");
+                    fmt = (opt->flag & VSH_OFLAG_REQ) ? _("<%s>...")
+                           : _("[<%s>]...");
                     break;
                 default:
                     assert(0);
@@ -11675,7 +11681,8 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
                     break;
                 case VSH_OT_ARGV:
                     /* Not really an option. */
-                    continue;
+                    snprintf(buf, sizeof(buf), _("<%s>"), opt->name);
+                    break;
                 default:
                     assert(0);
                 }
@@ -13112,7 +13119,7 @@ vshReadlineOptionsGenerator(const char *text, int state)
 
         list_index++;
 
-        if (opt->type == VSH_OT_DATA)
+        if (opt->type == VSH_OT_DATA || opt->type == VSH_OT_ARGV)
             /* ignore non --option */
             continue;