Bug 949373

Summary: Issues about virsh with incorrect argument
Product: Red Hat Enterprise Linux 7 Reporter: tingting zheng <tzheng>
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.0CC: acathrow, cwei, dyuan, eblake, lcui, mzhan
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-1.0.5-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-13 12:35:19 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 tingting zheng 2013-04-08 02:38:03 UTC
Description
Issues about virsh with incorrect argument

Version:
libvirt-1.0.3-1.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Run virsh with incorrect argument.(Different output with rhel6.4,see Additional info)
# virsh --debu
error: option '-d' requires an argument

# virsh ---debug
error: unsupported option '-

# virsh --debugg
error: unsupported option '-

2.Run virsh with --,no handle for it.(Same with rhel6.4,not sure whether it is designed by this)
# virsh -- list --all
 Id    Name                           State
----------------------------------------------------

# virsh --
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh #


Actual results:
As describes.

Expected results:
Improve the error info to be correct and clear.

Additional info:
On rhel6.4:
# virsh --debu
virsh: option '--debug' requires an argument
error: unsupported option '-?'. See --help.

# virsh ---debug
virsh: unrecognized option '---debug'
error: unsupported option '-?'. See --help.

# virsh --debugg
virsh: unrecognized option '--debugg'
error: unsupported option '-?'. See --help.

# virsh --
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh #

Comment 2 Eric Blake 2013-04-08 17:25:30 UTC
(In reply to comment #0)
> Description
> Issues about virsh with incorrect argument
> 
> Version:
> libvirt-1.0.3-1.el7.x86_64
> 
> How reproducible:
> 100%
> 
> Steps to Reproduce:
> 1.Run virsh with incorrect argument.(Different output with rhel6.4,see
> Additional info)
> # virsh --debu
> error: option '-d' requires an argument

'--debu' is unambiguously short for '--debug', and since '--debug' and '-d' are synonyms, the output is technically correct.  But yes, it would be nice if the error message included the name of the option as the user typed it instead of canonicalizing it to the short option variant.

> 
> # virsh ---debug
> error: unsupported option '-

This is correct - there is no option that starts with three dashes.  But again, it would be nice if the error message included the entire option as the user typed it, instead of just the first character (the third dash) that caused the problem.  Furthermore, the output is unbalanced (missing a close '), so that should be fixed, even if we don't figure out how to replay what the user typed.

> 
> # virsh --debugg
> error: unsupported option '-

Again, there is no long option named --debugg, but again, displaying the full text of what the user typed would be better.

> 
> 2.Run virsh with --,no handle for it.(Same with rhel6.4,not sure whether it
> is designed by this)
> # virsh -- list --all

This is not a bug, but behavior required by POSIX.  The '--' marker must be silently ignored, and states that all remaining arguments are taken as arguments instead of options even if they start with '-'.  There is nothing to fix here.

> # virsh --
> Welcome to virsh, the virtualization interactive terminal.

Again, nothing to fix.

Comment 3 Ján Tomko 2013-04-30 08:39:55 UTC
The fix is now pushed upstream:
commit 53531e16bf7cfe4fe20a4fe132f8199dcd474245
Author:     Ján Tomko <jtomko>
AuthorDate: 2013-04-29 19:12:17 +0200
Commit:     Ján Tomko <jtomko>
CommitDate: 2013-04-30 10:23:44 +0200

    virsh: fix incorrect argument errors for long options
    
    For long options, print:
    * the option as specified by the user if it's unknown
    * the canonical long option if its argument is not
      a number (and should be)
    
    And for missing arguments, print both the short and
    the long option name.
    (Doing only one of those would require either parsing
    argv ourselves or let getopt print the errors, since
    we can't tell long and short options apart by optopt
    or longindex)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=949373
    
    Unsupported long option:
    
    $ virsh --pm
    Before:
    error: unsupported option '-
    After:
    error: unsupported option '--pm'. See --help.
    
    Missing parameter:
    
    $ virsh --deb
    Before:
    error: option '-d' requires an argument
    After:
    error: option '-d'/'--debug' requires an argument
    
    $ virsh -rd
    Before:
    error: option '-d' requires an argument
    After:
    error: option '-d'/'--debug' requires an argument
    
    Non-numeric parameter:
    
    $ virsh --deb duck
    Before:
    error: option -d takes a numeric argument
    After:
    error: option --debug takes a numeric argument

Comment 4 zzhong@redhat.com 2013-05-08 01:02:43 UTC
can reporduce with libvirt-1.0.3-1.el7.x86_64
verify with build:
libvirt-1.0.5-1.el7.x86_64

step:
1.Run virsh with incorrect argument.(Different output with rhel6.4,see Additional info)
#virsh --debu
error: option '-d'/'--debug' requires an argument

#virsh ---debug
error: unsupported option '---debug'. See --help.

#virsh --debugg
error: unsupported option '--debugg'. See --help.

2.Run virsh with --,no handle for it.
#virsh -- list --all
Id Name State
----------------------------------------------------
24 test running
29 bb running
- test1 shut off
- win-mig shut off
- win7 shut off

#virsh --
Welcome to virsh, the virtualization interactive terminal.

Type: 'help' for help with commands
'quit' to quit

virsh#

#virsh --pm
error: unsupported option '--pm'. See --help.

#virsh --deb
error: option '-d'/'--debug' requires an argument

#virsh -rd
error: option '-d'/'--debug' requires an argument

#virsh --deb duck
error: option --debug takes a numeric argument

with wrong argument,it will have the error info to be correct and clear.verification passed

Comment 5 Ludek Smid 2014-06-13 12:35:19 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.