Skip to content

Commit

Permalink
tools/kvm_stat: suppress usage information on command line errors
Browse files Browse the repository at this point in the history
Errors while parsing the '-g' command line argument result in display of
usage information prior to the error message. This is a bit confusing,
as the command line is syntactically correct.
To reproduce, run 'kvm_stat -g' and specify a non-existing or inactive
guest.

Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Stefan Raspl authored and Paolo Bonzini committed Dec 14, 2017
1 parent 08e20a6 commit 822cfe3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tools/kvm/kvm_stat/kvm_stat
Original file line number Diff line number Diff line change
Expand Up @@ -1453,16 +1453,13 @@ Press any other key to refresh statistics immediately.
try:
pids = Tui.get_pid_from_gname(val)
except:
raise optparse.OptionValueError('Error while searching for guest '
'"{}", use "-p" to specify a pid '
'instead'.format(val))
sys.exit('Error while searching for guest "{}". Use "-p" to '
'specify a pid instead?'.format(val))
if len(pids) == 0:
raise optparse.OptionValueError('No guest by the name "{}" '
'found'.format(val))
sys.exit('Error: No guest by the name "{}" found'.format(val))
if len(pids) > 1:
raise optparse.OptionValueError('Multiple processes found (pids: '
'{}) - use "-p" to specify a pid '
'instead'.format(" ".join(pids)))
sys.exit('Error: Multiple processes found (pids: {}). Use "-p" '
'to specify the desired pid'.format(" ".join(pids)))
parser.values.pid = pids[0]

optparser = optparse.OptionParser(description=description_text,
Expand Down

0 comments on commit 822cfe3

Please sign in to comment.