提交 c60ece26 编写于 作者: C Cleber Rosa

avocado/__main__.py: rework module entry point

The following things were changed and for the following reasons:

1) Remove the current hack to force the program name at the module
entry point, for obvious reasons.

2) Return the exit status code, for obvious reasons.

3) Add some safety with a `__main__` check, because Sphinx will
load the avocado module in such a way that the avocado app is run
and the build fails. This is true on my system, and may be the case
on others.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 e75a9200
......@@ -6,8 +6,6 @@ import sys
from avocado.cli.app import AvocadoApp
if sys.argv[0].endswith('__main__.py'):
sys.argv[0] = 'python -m avocado'
main = AvocadoApp()
main.run()
if __name__ == '__main__':
main = AvocadoApp()
sys.exit(main.run())
......@@ -22,6 +22,9 @@ import argparse
from avocado.version import VERSION
PROG = 'avocado'
DESCRIPTION = 'Avocado Test Runner'
class Parser(object):
......@@ -31,9 +34,9 @@ class Parser(object):
def __init__(self):
self.application = argparse.ArgumentParser(
prog='avocado',
prog=PROG,
add_help=False, # see parent parsing
description='Avocado Test Runner')
description=DESCRIPTION)
self.application.add_argument('-v', '--version', action='version',
version='Avocado %s' % VERSION)
self.application.add_argument('--plugins', action='store',
......@@ -49,8 +52,10 @@ class Parser(object):
"""
self.args, _ = self.application.parse_known_args()
# Use parent parsing to avoid to break the output of --help option
self.application = argparse.ArgumentParser(parents=[self.application])
# Use parent parsing to avoid breaking the output of --help option
self.application = argparse.ArgumentParser(prog=PROG,
description=DESCRIPTION,
parents=[self.application])
# Subparsers where Avocado subcommands are plugged
self.subcommands = self.application.add_subparsers(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册