Fix up `zuul --version`
argparse does not support optional subparser, hence the `zuul` client command would always require to be passed a sub command. That prevented `zuul --version` from showing up with a 'too few arguments' error. I found out add_argument() has a action='version' which would print the content of the 'version' argument and exit. Change-Id: I553d3b2ab7aa04865e44559135adc5a7640307edchanges/29/66629/3
parent
f39b9ca80c
commit
aabb686bc7
|
@ -39,7 +39,8 @@ class Client(object):
|
|||
help='specify the config file')
|
||||
parser.add_argument('-v', dest='verbose', action='store_true',
|
||||
help='verbose output')
|
||||
parser.add_argument('--version', dest='version', action='store_true',
|
||||
parser.add_argument('--version', dest='version', action='version',
|
||||
version=self._get_version(),
|
||||
help='show zuul version')
|
||||
|
||||
subparsers = parser.add_subparsers(title='commands',
|
||||
|
@ -67,6 +68,10 @@ class Client(object):
|
|||
|
||||
self.args = parser.parse_args()
|
||||
|
||||
def _get_version(self):
|
||||
from zuul.version import version_info as zuul_version_info
|
||||
return "Zuul version: %s" % zuul_version_info.version_string()
|
||||
|
||||
def read_config(self):
|
||||
self.config = ConfigParser.ConfigParser()
|
||||
if self.args.config:
|
||||
|
@ -89,11 +94,6 @@ class Client(object):
|
|||
self.read_config()
|
||||
self.setup_logging()
|
||||
|
||||
if self.args.version:
|
||||
from zuul.version import version_info as zuul_version_info
|
||||
print "Zuul version: %s" % zuul_version_info.version_string()
|
||||
sys.exit(0)
|
||||
|
||||
self.server = self.config.get('gearman', 'server')
|
||||
if self.config.has_option('gearman', 'port'):
|
||||
self.port = self.config.get('gearman', 'port')
|
||||
|
|
|
@ -66,10 +66,15 @@ class Server(object):
|
|||
help='validate layout file syntax (optionally '
|
||||
'providing the path to a file with a list of '
|
||||
'available job names)')
|
||||
parser.add_argument('--version', dest='version', action='store_true',
|
||||
parser.add_argument('--version', dest='version', action='version',
|
||||
version=self._get_version(),
|
||||
help='show zuul version')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
def _get_version(self):
|
||||
from zuul.version import version_info as zuul_version_info
|
||||
return "Zuul version: %s" % zuul_version_info.version_string()
|
||||
|
||||
def read_config(self):
|
||||
self.config = ConfigParser.ConfigParser()
|
||||
if self.args.config:
|
||||
|
@ -227,11 +232,6 @@ def main():
|
|||
server = Server()
|
||||
server.parse_arguments()
|
||||
|
||||
if server.args.version:
|
||||
from zuul.version import version_info as zuul_version_info
|
||||
print "Zuul version: %s" % zuul_version_info.version_string()
|
||||
sys.exit(0)
|
||||
|
||||
server.read_config()
|
||||
|
||||
if server.args.layout:
|
||||
|
|
Loading…
Reference in New Issue