diff mbox

[v2,08/11] tools/kvm_stat: suppress usage information on command line errors

Message ID 20171211112529.33706-9-raspl@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Raspl Dec. 11, 2017, 11:25 a.m. UTC
From: Stefan Raspl <stefan.raspl@de.ibm.com>

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>
---
 tools/kvm/kvm_stat/kvm_stat | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Paolo Bonzini Dec. 12, 2017, 3:53 p.m. UTC | #1
On 11/12/2017 12:25, Stefan Raspl wrote:
>          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))

Maybe:

Error while searching for guest "{}". Use "-p" to specify a pid instead?

Thanks,

Paolo
Stefan Raspl Dec. 12, 2017, 6:09 p.m. UTC | #2
On 12.12.2017 16:53, Paolo Bonzini wrote:
> On 11/12/2017 12:25, Stefan Raspl wrote:
>>          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))
> 
> Maybe:
> 
> Error while searching for guest "{}". Use "-p" to specify a pid instead?

Yeah - 2 short sentences instead of a single longer one...why not?

Ciao,
Stefan
diff mbox

Patch

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 29c56f3a05dc..6ca18d15488e 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -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 a pid instead'.format(" ".join(pids)))
         parser.values.pid = pids[0]
 
     optparser = optparse.OptionParser(description=description_text,