2323import textwrap
2424
2525from robot .errors import DataError , Information , FrameworkError
26+ from robot .version import get_full_version
2627
2728from misc import plural_or_not
2829from encoding import decode_output , decode_from_file_system
@@ -52,17 +53,17 @@ class ArgumentParser:
5253 \s*$
5354 ''' , re .VERBOSE | re .IGNORECASE )
5455
55- def __init__ (self , usage , version = None , arg_limits = None ):
56+ def __init__ (self , usage , name = None , version = None , arg_limits = None ):
5657 """Available options and tool name are read from the usage.
5758
5859 Tool name is got from the first row of the usage. It is either the
5960 whole row or anything before first ' -- '.
6061 """
6162 if not usage :
6263 raise FrameworkError ('Usage cannot be empty' )
64+ self .name = name or usage .splitlines ()[0 ].split (' -- ' )[0 ].strip ()
65+ self .version = version or get_full_version ()
6366 self ._usage = usage
64- self ._name = usage .splitlines ()[0 ].split (' -- ' )[0 ].strip ()
65- self ._version = version
6667 self ._arg_limits = arg_limits
6768 self ._short_opts = ''
6869 self ._long_opts = []
@@ -367,8 +368,8 @@ def _get_available_escapes(self):
367368
368369 def _raise_help (self ):
369370 msg = self ._usage
370- if self ._version :
371- msg = msg .replace ('<VERSION>' , self ._version )
371+ if self .version :
372+ msg = msg .replace ('<VERSION>' , self .version )
372373 def replace_escapes (res ):
373374 escapes = 'Available escapes: ' + self ._get_available_escapes ()
374375 lines = textwrap .wrap (escapes , width = len (res .group (2 )))
@@ -378,9 +379,7 @@ def replace_escapes(res):
378379 raise Information (msg )
379380
380381 def _raise_version (self ):
381- if not self ._version :
382- raise FrameworkError ('Version not set' )
383- raise Information ('%s %s' % (self ._name , self ._version ))
382+ raise Information ('%s %s' % (self .name , self .version ))
384383
385384 def _raise_option_multiple_times_in_usage (self , opt ):
386385 raise FrameworkError ("Option '%s' multiple times in usage" % opt )
0 commit comments