kas: Simplify setup of plugin argument parsers

By defining the plugin name and help message as attributes of the plugin
class we can move the argument parser creation up into the
kas_get_argparser() function. This will allow us to further reduce
duplication in following commits.

Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Paul Barker 2020-06-15 22:03:27 +02:00 committed by Jan Kiszka
parent 23277836c4
commit a37d72ea7c
3 changed files with 38 additions and 36 deletions

View File

@ -46,30 +46,31 @@ class Build:
This class implements the build plugin for kas.
"""
@classmethod
def get_argparser(cls, parser):
"""
Returns an a parser for the build plugin
"""
bld_psr = parser.add_parser('build',
help='Checks out all necessary '
'repositories and builds using '
'bitbake as specificed in the '
'configuration file.')
name = 'build'
helpmsg = (
'Checks out all necessary repositories and builds using bitbake as '
'specificed in the configuration file.'
)
bld_psr.add_argument('config',
help='Config file')
bld_psr.add_argument('extra_bitbake_args',
nargs='*',
help='Extra arguments to pass to bitbake')
bld_psr.add_argument('--target',
action='append',
help='Select target to build')
bld_psr.add_argument('-c', '--cmd', '--task', dest='task',
help='Select which task should be executed')
bld_psr.add_argument('--skip',
help='Skip build steps',
default=[])
@classmethod
def setup_parser(cls, parser):
"""
Setup the argument parser for the build plugin
"""
parser.add_argument('config',
help='Config file')
parser.add_argument('extra_bitbake_args',
nargs='*',
help='Extra arguments to pass to bitbake')
parser.add_argument('--target',
action='append',
help='Select target to build')
parser.add_argument('-c', '--cmd', '--task', dest='task',
help='Select which task should be executed')
parser.add_argument('--skip',
help='Skip build steps',
default=[])
def run(self, args):
"""

View File

@ -121,7 +121,8 @@ def kas_get_argparser():
ext_plugin.load()
for plugin in getattr(kasplugin, 'plugins', []):
plugin.get_argparser(subparser)
plugin_parser = subparser.add_parser(plugin.name, help=plugin.helpmsg)
plugin.setup_parser(plugin_parser)
return parser

View File

@ -47,24 +47,24 @@ class Shell:
Implements a kas plugin that opens a shell within the kas environment.
"""
@classmethod
def get_argparser(cls, parser):
"""
Returns a parser for the shell plugin
"""
sh_prs = parser.add_parser('shell',
help='Run a shell in the build '
'environment.')
name = 'shell'
helpmsg = 'Run a shell in the build environment.'
sh_prs.add_argument('config',
@classmethod
def setup_parser(cls, parser):
"""
Setup the argument parser for the shell plugin
"""
parser.add_argument('config',
help='Config file')
sh_prs.add_argument('--skip',
parser.add_argument('--skip',
help='Skip build steps',
default=[])
sh_prs.add_argument('-k', '--keep-config-unchanged',
parser.add_argument('-k', '--keep-config-unchanged',
help='Skip steps that change the configuration',
action='store_true')
sh_prs.add_argument('-c', '--command',
parser.add_argument('-c', '--command',
help='Run command',
default='')