Bug 1018369 - virsh documentation error: option --domain already seen
virsh documentation error: option --domain already seen
Status: CLOSED WONTFIX
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.0
x86_64 Linux
unspecified Severity low
: rc
: ---
Assigned To: Eric Blake
lijuan men
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-11 15:12 EDT by Chris Evich
Modified: 2016-12-21 15:41 EST (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-12-21 15:41:30 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Chris Evich 2013-10-11 15:12:11 EDT
Description of problem:
virsh parameter parsing enforces positional ordering even when argument options passed

Version-Release number of selected component (if applicable):
libvirt-1.1.1-5.el7.x86_64

How reproducible:
Very

Steps to Reproduce:
1. Shutdown vm
2. virsh attach-device /path/to.xml --domain virt-tests-vm1 --config

Actual results:
exit 1 stdout: '' stderr: 'error: option --domain already seen'

Expected results:
exit 0 stdout: 'Device attached successfully' stderr: ''

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 - In case code-change is non-trivial.
Comment 1 Eric Blake 2013-10-11 15:25:12 EDT
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.
Comment 2 Eric Blake 2013-10-11 15:28:56 EDT
(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).
Comment 4 Chris Evich 2013-10-11 16:44:10 EDT
Yeah, not surprised that messing with the parser would be difficult.  I also suspect there are many other commands with a similarly challenged help:

  SYNOPSIS
    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:

  SYNOPSIS
    attach-device [--domain] <domain> [--file] <file> [--persistent] [--config] 
                  [--live] [--current]

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".
Comment 9 Eric Blake 2015-07-28 11:24:56 EDT
As a doc fix, this should be fairly simple to get something in place to help the situation.
Comment 11 Ademar Reis 2016-12-21 15:41:30 EST
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.

Note You need to log in before you can comment on or make changes to this bug.