Skip to content

Commit ba1baf4

Browse files
committed
DNM: zephyr: west: add gigadevice west extension commands
add gigadevice west extension commands Signed-off-by: YuLong Yao <[email protected]>
1 parent 024ed9e commit ba1baf4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

zephyr/west/gigadevice.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2023 YuLong Yao <[email protected]>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
'''gigadevice.py
6+
7+
Gigadevice west extension for prepare develop environment.'''
8+
9+
from textwrap import dedent # just for nicer code indentation
10+
11+
from west.commands import WestCommand # your extension must subclass this
12+
from west import log # use this for user output
13+
14+
15+
class Gigadevice(WestCommand):
16+
17+
def __init__(self):
18+
super().__init__(
19+
'gigadevice', # gets stored as self.name
20+
'Gigadevice tools for west framework', # self.help
21+
# self.description:
22+
dedent('''
23+
Gigadevice tools for west framework
24+
25+
Prepare develop environment for Gigadevice MCU.'''))
26+
27+
def do_add_parser(self, parser_adder):
28+
# This is a bit of boilerplate, which allows you full control over the
29+
# type of argparse handling you want. The "parser_adder" argument is
30+
# the return value of an argparse.ArgumentParser.add_subparsers() call.
31+
parser = parser_adder.add_parser(self.name,
32+
help=self.help,
33+
description=self.description)
34+
35+
# Add some example options using the standard argparse module API.
36+
parser.add_argument('command', help='command to run')
37+
38+
return parser # gets stored as self.parser
39+
40+
def do_run(self, args, unknown_args):
41+
# This gets called when the user runs the command, e.g.:
42+
#
43+
# $ west my-command-name -o FOO BAR
44+
# --optional is FOO
45+
# required is BAR
46+
match args.command:
47+
case 'install':
48+
log.inf('command is', args.command)
49+
log.inf('we can install some pack for pyocd')
50+
log.inf('RUN: pyocd pack install gd32e103')
51+
case _:
52+
log.inf('command is', args.command)

zephyr/west/west-commands.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2023 YuLong Yao <[email protected]>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
west-commands:
6+
- file: zephyr/west/gigadevice.py
7+
commands:
8+
- name: gigadevice
9+
class: Gigadevice
10+
help: Gigadevice tools for west framework.

0 commit comments

Comments
 (0)