Bug 1018369

Summary: virsh documentation error: option --domain already seen
Product: Red Hat Enterprise Linux 7 Reporter: Chris Evich <cevich>
Component: libvirtAssignee: Eric Blake <eblake>
Status: CLOSED WONTFIX QA Contact: lijuan men <lmen>
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.0CC: dyuan, eblake, mzhan, rbalakri, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-12-21 20:41:30 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Chris Evich 2013-10-11 19:12:11 UTC
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 19:25:12 UTC
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 19:28:56 UTC
(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 20:44:10 UTC
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 15:24:56 UTC
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 20:41:30 UTC
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.