Red Hat Bugzilla – Bug 1018369
virsh documentation error: option --domain already seen
Last modified: 2016-12-21 15:41:30 EST
Description of problem:
virsh parameter parsing enforces positional ordering even when argument options passed
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Shutdown vm
2. virsh attach-device /path/to.xml --domain virt-tests-vm1 --config
exit 1 stdout: '' stderr: 'error: option --domain already seen'
exit 0 stdout: 'Device attached successfully' stderr: ''
It works fine if --domain opt comes before /path/to.xml, so this possibly could be fixed with fairly simple man and --help doc. update - In case code-change is non-trivial.
Not (necessarily) a bug. The parser is currently coded to non-lookahead parsing, so:
attach-device /path/to.xml ...
is parsed as:
attach-device --domain /path/to.xml ...
regardless of the contents of '...'.
It _might_ be possible to change that to do a full-scan parse, where all explicit options are removed from the set of options that must then be mapped to remaining positional arguments. But doing that might break existing clients that are used to the current parse rules. And it is also more complex:
attach-device --file --domain --config foo
should parse the same as:
attach-device --domain=foo --file=--domain --config
but that means you can't just look for arguments with leading '--', you also have to know the context of whether the previous argument was an option that requires data vs. a boolean option.
Finally, you can ALWAYS be more explicit and provide:
attach-device --file=/path/to.xml --domain=virt-tests-vm1 --config
if you want to avoid positional parsing, so it's not like the current parsing rules are actively preventing you from constructing a valid command line. As such, I'm inclined to close this as not a bug, unless I hear further good arguments why we should make a change.
(In reply to Chris Evich from comment #0)
> Additional info:
> It works fine if --domain opt comes before /path/to.xml, so this possibly
> could be fixed with fairly simple man and --help doc. update
If we go the improved doc route, what wording would you suggest? (I'm a bit biased since I wrote the bulk of the current parse code, and am worried that code changes could risk unintended back-compat breakage in spite of our existing testsuite on option parsing).
Yeah, not surprised that messing with the parser would be difficult. I also suspect there are many other commands with a similarly challenged help:
attach-device <domain> <file> [--persistent] [--config] [--live] [--current]
No info is provided about --domain/--file. However, I think maybe just a simple tweak could fix this, How about:
attach-device [--domain] <domain> [--file] <file> [--persistent] [--config]
Same thing for the man page:
attach-device [--domain] domain [--file] FILE [[[--live] [--config] |
[--current]] | [--persistent]]
Another idea is to just add a blanket statement to the man page Description. It already covers a lot of the usage anyway. How about something like:
"Any [OPTION] with equivalent [ARG] will be interpreted in the same order as [ARG]. For example, <domain> <file> could be --domain <domain> --file <file>, but not in any other order".
As a doc fix, this should be fairly simple to get something in place to help the situation.
Discussed this with Eric and decided it's not worth fixing. The behavior and documentation have been like this forever and (other) users are not complaining.