提交 4e650259 编写于 作者: E Eric Blake

virsh: Treat any command name starting with # as comment

As the previous commit mentioned, argv mode (such as when you feed
virsh via stdin with <<\EOF instead of via a single shell argument)
didn't permit comments. Do this by treating any command name token
that starts with # as a comment which silently eats all remaining
arguments to the next newline or semicolon.

Note that batch mode recognizes unquoted # at the start of any word as
a command as part of the tokenizer, while this patch only treats # at
the start of the command word as a comment (any other # remaining by
the time vshCommandParse() is processing things was already quoted
during the tokenzier, and as such was probably intended as the actual
argument to the command word earlier in the line).

Now I can do something like:

$ virsh -c test:///default <<EOF
  # setup
  snapshot-create-as test s1
  snapshot-create-as test s2
  # check
  snapshot-list test --name
EOF
Signed-off-by: NEric Blake <eblake@redhat.com>
Acked-by: NMichal Privoznik <mprivozn@redhat.com>
上级 834f64ca
......@@ -423,6 +423,7 @@ mymain(void)
DO_TEST(44, "a # b\n", "echo a '#' b");
DO_TEST(45, "a # b\n", "echo a \\# b");
DO_TEST(46, "a\n", "#unbalanced; 'quotes\"\necho a # b");
DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored");
# undef DO_TEST
......
......@@ -35,7 +35,8 @@ will be clear for each of those commands. Note: it is permissible to
give numeric names to domains, however, doing so will result in a
domain that can only be identified by domain id. In other words, if a
numeric value is supplied it will be interpreted as a domain id, not
as a name.
as a name. Any I<command> starting with B<#> is treated as a comment
and silently ignored, all other unrecognized I<command>s are diagnosed.
The B<virsh> program can be used either to run one I<COMMAND> by giving the
command and its arguments on the shell command line, or a I<COMMAND_STRING>
......
......@@ -18,7 +18,9 @@ The basic structure of most virt-admin usage is:
virt-admin [OPTION]... <command> [ARG]...
Where I<command> is one of the commands listed below.
Where I<command> is one of the commands listed below. Any I<command>
starting with B<#> is treated as a comment and silently ignored, all
other unrecognized I<command>s are diagnosed.
The B<virt-admin> program can be used either to run one I<COMMAND> by giving the
command and its arguments on the shell command line, or a I<COMMAND_STRING>
......
......@@ -1437,8 +1437,15 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
}
if (cmd == NULL) {
/* first token must be command name */
if (!(cmd = vshCmddefSearch(tkdata))) {
/* first token must be command name or comment */
if (*tkdata == '#') {
do {
VIR_FREE(tkdata);
tk = parser->getNextArg(ctl, parser, &tkdata, false);
} while (tk == VSH_TK_ARG);
VIR_FREE(tkdata);
break;
} else if (!(cmd = vshCmddefSearch(tkdata))) {
if (!partial)
vshError(ctl, _("unknown command: '%s'"), tkdata);
goto syntaxError; /* ... or ignore this command only? */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册