Skip to content

Commit fa29a07

Browse files
pdgendtmmahadevan108
authored andcommitted
doc: develop: west: Add alias documentation
Add documentation and examples for west aliases. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent e020f31 commit fa29a07

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

doc/develop/west/alias.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.. _west-aliases:
2+
3+
West aliases
4+
############
5+
6+
West allows to add alias commands to the local, global or system configuration files.
7+
These aliases make it easy to add shortcuts for frequently used, or hard to memorize
8+
commands for ease of development.
9+
10+
Similar to how ``git`` aliases work, the alias command is replaced with the alias'
11+
full text and parsed as a new shell argument list (using the Python function
12+
`shlex.split()`_ internally to split the value). This enables adding argument
13+
parameters as they were passed to the original command. Spaces are considered
14+
argument separators; use proper escaping if arguments shouldn't be split.
15+
16+
.. _shlex.split(): https://docs.python.org/3/library/shlex.html#shlex.split
17+
18+
To add a new alias simply call the ``west config`` command:
19+
20+
.. code-block:: shell
21+
22+
west config alias.mylist "list -f '{name} {revision}'"
23+
24+
To list aliases, use :samp:`west help {some_alias}`.
25+
26+
Recursive aliases are allowed as an alias command can contain other aliases, effectively
27+
building more complex but easy-to-remember commands.
28+
29+
It is possible to override an existing command, for example to pass default arguments:
30+
31+
.. code-block:: shell
32+
33+
west config alias.update "update -o=--depth=1 -n"
34+
35+
.. warning::
36+
37+
Overriding/shadowing other or built-in commands is an advanced use case, it can lead to
38+
strange side-effects and should be done with great care.
39+
40+
Examples
41+
--------
42+
43+
Add ``west run`` and ``west menuconfig`` shortcuts to your global configuration to
44+
call ``west build`` with the corresponding CMake targets:
45+
46+
.. code-block:: shell
47+
48+
west config --global alias.run "build --pristine=never --target run"
49+
west config --global alias.menuconfig "build --pristine=never --target menuconfig"
50+
51+
Create an alias for the sample you are actively developing with additional options:
52+
53+
.. code-block:: shell
54+
55+
west config alias.sample "build -b native_sim samples/hello_world -t run -- -DCONFIG_ASSERT=y"
56+
57+
Override ``west update`` to check a local cache:
58+
59+
.. code-block:: shell
60+
61+
west config alias.update "update --path-cache $HOME/.cache/zephyrproject"

doc/develop/west/config.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ commands are documented in the pages for those commands.
130130

131131
* - Option
132132
- Description
133+
* - :samp:`alias.{ALIAS}`
134+
- String. If non-empty the ``<ALIAS>`` can be used as a west command.
135+
See :ref:`west-aliases`.
133136
* - ``color.ui``
134137
- Boolean. If ``true`` (the default), then west output is colorized when
135138
stdout is a terminal.

doc/develop/west/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ each command.
3737
workspaces.rst
3838
manifest.rst
3939
config.rst
40+
alias.rst
4041
extensions.rst
4142
build-flash-debug.rst
4243
sign.rst

0 commit comments

Comments
 (0)