DO_TEST(30, "--shell a\n",
"echo \t '-'\"-\" \t --shell \t a");
+ /* Tests of alias handling. */
+ DO_TEST(31, "hello\n", "echo", "--string", "hello");
+ DO_TEST(32, "hello\n", "echo --string hello");
+ DO_TEST(33, "hello\n", "echo", "--str", "hello");
+ DO_TEST(34, "hello\n", "echo --str hello");
+
# undef DO_TEST
VIR_FREE(custom_uri);
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 */
+ VSH_OT_ARGV, /* remaining arguments */
+ VSH_OT_ALIAS, /* alternate spelling for a later argument */
} vshCmdOptType;
/*
const char *name; /* the name of option, or NULL for list end */
vshCmdOptType type; /* option type */
unsigned int flags; /* flags */
- const char *help; /* non-NULL help string */
+ const char *help; /* non-NULL help string; or for VSH_OT_ALIAS
+ * the name of a later public option */
} vshCmdOptDef;
/*
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")},
+ {"str", VSH_OT_ALIAS, 0, "string"},
{"string", VSH_OT_ARGV, 0, N_("arguments to echo")},
{NULL, 0, 0, NULL}
};
return -1; /* bool options can't be mandatory */
continue;
}
+ if (opt->type == VSH_OT_ALIAS) {
+ int j;
+ if (opt->flags || !opt->help)
+ return -1; /* alias options are tracked by the original name */
+ for (j = i + 1; cmd->opts[j].name; j++) {
+ if (STREQ(opt->help, cmd->opts[j].name))
+ break;
+ }
+ if (!cmd->opts[j].name)
+ return -1; /* alias option must map to a later option name */
+ continue;
+ }
if (opt->flags & VSH_OFLAG_REQ_OPT) {
if (opt->flags & VSH_OFLAG_REQ)
*opts_required |= 1 << i;
const vshCmdOptDef *opt = &cmd->opts[i];
if (STREQ(opt->name, name)) {
+ if (opt->type == VSH_OT_ALIAS) {
+ name = opt->help;
+ continue;
+ }
if ((*opts_seen & (1 << i)) && opt->type != VSH_OT_ARGV) {
vshError(ctl, _("option --%s already seen"), name);
return NULL;
: _("[<%s>]...");
}
break;
+ case VSH_OT_ALIAS:
+ /* aliases are intentionally undocumented */
+ continue;
default:
assert(0);
}
shortopt ? _("[--%s] <string>") : _("<%s>"),
opt->name);
break;
+ case VSH_OT_ALIAS:
+ continue;
default:
assert(0);
}
must poll periodically to detect that the guest completed the
operation.
+B<virsh> strives for backward compatibility. Although the B<help>
+command only lists the preferred usage of a command, if an older
+version of B<virsh> supported an alternate spelling of a command or
+option (such as I<--tunnelled> instead of I<--tunneled>), then
+scripts using that older spelling will continue to work.
+
=head1 GENERIC COMMANDS
The following commands are generic i.e. not specific to a domain.