Seperated argument parser creation from main kas entry point
With Sphinx it is possible to create the command line documentation automatically if there is a function that returns just the command line parser. Currently the creation of the argument parser is rather entangled with the rest of kas. This patches seperates this. Signed-off-by: Claudius Heine <ch@denx.de>
This commit is contained in:
committed by
Daniel Wagner
parent
546b51f450
commit
503fd3d47a
38
kas/kas.py
38
kas/kas.py
@@ -42,10 +42,16 @@ try:
|
||||
except ImportError:
|
||||
HAVE_COLORLOG = False
|
||||
|
||||
from .build import Build
|
||||
from .shell import Shell
|
||||
from . import __version__
|
||||
|
||||
# Import kas plugins
|
||||
# Since they are added by decorators, they don't need to be called,
|
||||
# just imported.
|
||||
# pylint: disable=unused-import
|
||||
from .libkas import kasplugin
|
||||
from . import build
|
||||
from . import shell
|
||||
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) Siemens AG, 2017'
|
||||
|
||||
@@ -90,12 +96,10 @@ def _atexit_handler(loop):
|
||||
os.killpg(os.getpid(), signal.SIGTERM)
|
||||
|
||||
|
||||
def kas(argv):
|
||||
def kas_get_argparser():
|
||||
"""
|
||||
The main entry point of kas.
|
||||
Creates a argparser for kas with all plugins.
|
||||
"""
|
||||
create_logger()
|
||||
|
||||
parser = argparse.ArgumentParser(description='Steer ebs-yocto builds')
|
||||
|
||||
parser.add_argument('--version', action='version',
|
||||
@@ -106,12 +110,22 @@ def kas(argv):
|
||||
help='Enable debug logging')
|
||||
|
||||
subparser = parser.add_subparsers(help='sub command help', dest='cmd')
|
||||
sub_cmds = [Build(subparser), Shell(subparser)]
|
||||
for ext_plugin in pkg_resources.iter_entry_points('kas.plugins'):
|
||||
ext_plugin.load()
|
||||
|
||||
for plugin in pkg_resources.iter_entry_points('kas.plugins'):
|
||||
cmd = plugin.load()
|
||||
sub_cmds.append(cmd(subparser))
|
||||
for plugin in getattr(kasplugin, 'plugins', []):
|
||||
plugin.get_argparser(subparser)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def kas(argv):
|
||||
"""
|
||||
The main entry point of kas.
|
||||
"""
|
||||
create_logger()
|
||||
|
||||
parser = kas_get_argparser()
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if args.debug:
|
||||
@@ -123,8 +137,8 @@ def kas(argv):
|
||||
loop.add_signal_handler(sig, interruption)
|
||||
atexit.register(_atexit_handler, loop=loop)
|
||||
|
||||
for cmd in sub_cmds:
|
||||
if cmd.run(args):
|
||||
for plugin in getattr(kasplugin, 'plugins', []):
|
||||
if plugin().run(args):
|
||||
return
|
||||
|
||||
parser.print_help()
|
||||
|
Reference in New Issue
Block a user