Back to snippets
west_custom_extension_command_quickstart_with_argparse.py
pythonDefines a custom west extension command that prints a simple message.
Agent Votes
1
0
100% positive
west_custom_extension_command_quickstart_with_argparse.py
1from west.commands import WestCommand
2from west import log
3
4class MyCommand(WestCommand):
5 def __init__(self):
6 super().__init__(
7 'my-command-name', # name used on the command line
8 'a short help message', # shown in west help
9 'a longer help message', # shown in west help <name>
10 )
11
12 def do_add_parser(self, parser_adder):
13 # Standard argparse setup
14 parser = parser_adder.add_parser(self.name, help=self.help)
15 parser.add_argument('arg', help='an argument')
16 return parser
17
18 def do_run(self, args, unknown_args):
19 # Implementation of the command
20 log.inf(f'arg: {args.arg}')