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:
parent
23277836c4
commit
a37d72ea7c
31
kas/build.py
31
kas/build.py
@ -46,28 +46,29 @@ 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
|
||||||
|
def setup_parser(cls, parser):
|
||||||
|
"""
|
||||||
|
Setup the argument parser for the build plugin
|
||||||
|
"""
|
||||||
|
|
||||||
|
parser.add_argument('config',
|
||||||
help='Config file')
|
help='Config file')
|
||||||
bld_psr.add_argument('extra_bitbake_args',
|
parser.add_argument('extra_bitbake_args',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
help='Extra arguments to pass to bitbake')
|
help='Extra arguments to pass to bitbake')
|
||||||
bld_psr.add_argument('--target',
|
parser.add_argument('--target',
|
||||||
action='append',
|
action='append',
|
||||||
help='Select target to build')
|
help='Select target to build')
|
||||||
bld_psr.add_argument('-c', '--cmd', '--task', dest='task',
|
parser.add_argument('-c', '--cmd', '--task', dest='task',
|
||||||
help='Select which task should be executed')
|
help='Select which task should be executed')
|
||||||
bld_psr.add_argument('--skip',
|
parser.add_argument('--skip',
|
||||||
help='Skip build steps',
|
help='Skip build steps',
|
||||||
default=[])
|
default=[])
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
24
kas/shell.py
24
kas/shell.py
@ -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='')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user