]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Add a VSH_OT_STRING argument for 'virsh echo'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 3 Apr 2024 05:07:57 +0000 (07:07 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 25 Apr 2024 12:13:19 +0000 (14:13 +0200)
The argument will be used for testing the command/option completer
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/vsh.c

index 1e8be2393e978258d5d44f4848dc18c55aefbec3..7853e7cc6d93017159ffce1297a0dd23678d2346 100644 (file)
@@ -3250,6 +3250,10 @@ const vshCmdOptDef opts_echo[] = {
      .type = VSH_OT_ALIAS,
      .help = "string=hello"
     },
+    {.name = "prefix",
+     .type = VSH_OT_STRING,
+     .help = N_("prefix the message")
+    },
     {.name = "string",
      .type = VSH_OT_ARGV,
      .positional = true,
@@ -3273,6 +3277,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
     bool xml = vshCommandOptBool(cmd, "xml");
     bool err = vshCommandOptBool(cmd, "err");
     bool split = vshCommandOptBool(cmd, "split");
+    const char *prefix;
     const vshCmdOpt *opt = NULL;
     g_autofree char *arg = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -3281,6 +3286,11 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
     VSH_EXCLUSIVE_OPTIONS_VAR(shell, split);
     VSH_EXCLUSIVE_OPTIONS_VAR(xml, split);
 
+    ignore_value(vshCommandOptString(ctl, cmd, "prefix", &prefix));
+
+    if (prefix)
+        virBufferAsprintf(&buf, "%s ", prefix);
+
     while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
         const char *curr = opt->data;