2019-05-09 00:05:38 +08:00
|
|
|
# Copyright (c) 2019 Nordic Semiconductor ASA
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
from west import log
|
|
|
|
from west.commands import WestCommand
|
|
|
|
|
|
|
|
# Relative to the folder where this script lives
|
|
|
|
COMPLETION_REL_PATH = 'completion/west-completion'
|
|
|
|
|
2022-08-31 20:31:35 +08:00
|
|
|
COMP_DESCRIPTION = '''\
|
|
|
|
Output shell completion scripts for west.
|
|
|
|
|
|
|
|
This command outputs completion scripts for different shells by printing them
|
|
|
|
to stdout. Using the completion scripts:
|
|
|
|
|
|
|
|
bash:
|
|
|
|
# one-time
|
|
|
|
source <(west completion bash)
|
|
|
|
# permanent
|
|
|
|
west completion bash > ~/west-completion.bash
|
|
|
|
# edit your .bashrc or .bash_profile and add:
|
|
|
|
source $HOME/west-completion.bash
|
|
|
|
|
|
|
|
zsh:
|
|
|
|
# one-time
|
|
|
|
source <(west completion zsh)
|
|
|
|
# permanent (might require sudo)
|
|
|
|
west completion zsh > "${fpath[1]}/_west"
|
|
|
|
|
2023-09-10 20:24:12 +08:00
|
|
|
fish:
|
|
|
|
# one-time
|
|
|
|
west completion fish | source
|
|
|
|
# permanent
|
|
|
|
west completion fish > $HOME/.config/fish/completions/west.fish
|
|
|
|
|
2022-08-31 20:31:35 +08:00
|
|
|
positional arguments:
|
|
|
|
source_dir application source directory
|
|
|
|
cmake_opt extra options to pass to cmake; implies -c
|
|
|
|
(these must come after "--" as shown above)
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2019-05-09 00:05:38 +08:00
|
|
|
class Completion(WestCommand):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
|
|
|
'completion',
|
|
|
|
# Keep this in sync with the string in west-commands.yml.
|
2022-08-31 20:31:35 +08:00
|
|
|
'output shell completion scripts',
|
|
|
|
COMP_DESCRIPTION,
|
2019-05-09 00:05:38 +08:00
|
|
|
accepts_unknown_args=False)
|
|
|
|
|
|
|
|
def do_add_parser(self, parser_adder):
|
|
|
|
parser = parser_adder.add_parser(
|
|
|
|
self.name,
|
|
|
|
help=self.help,
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
description=self.description)
|
|
|
|
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-10 07:53:00 +08:00
|
|
|
# Remember to update west-completion.bash if you add or remove
|
|
|
|
# flags
|
2023-09-10 20:24:12 +08:00
|
|
|
parser.add_argument('shell', nargs=1, choices=['bash', 'zsh', 'fish'],
|
2022-08-31 20:31:35 +08:00
|
|
|
help='''Shell that which the completion
|
|
|
|
script is intended for.''')
|
2019-05-09 00:05:38 +08:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def do_run(self, args, unknown_args):
|
|
|
|
cf = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
|
|
|
*COMPLETION_REL_PATH.split('/'))
|
|
|
|
|
|
|
|
cf += '.' + args.shell[0]
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open(cf, 'r') as f:
|
|
|
|
print(f.read())
|
|
|
|
except FileNotFoundError as e:
|
2019-09-02 21:28:02 +08:00
|
|
|
log.die('Unable to find completion file: {}'.format(e))
|