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

View File

@ -121,7 +121,8 @@ def kas_get_argparser():
ext_plugin.load() ext_plugin.load()
for plugin in getattr(kasplugin, 'plugins', []): 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 return parser

View File

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