Skip to content

Commit 7cc35e4

Browse files
committed
feat(cli): add autocompletions
1 parent 14e5d93 commit 7cc35e4

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

docs/en/installation.rst

+38
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,41 @@ If updating directly is unavoidable, make sure you update to a compatible versio
6868
::
6969

7070
$ pip install esptool==3.3.2
71+
72+
Shell completions
73+
-----------------
74+
75+
To activate autocompletion, you can manually add commands provided below to your shell's config file
76+
or run them in your current terminal session for one-time activation.
77+
You will likely have to restart or re-login for the autocompletion to start working.
78+
79+
bash:
80+
::
81+
82+
eval "$(register-python-argcomplete esptool.py espsecure.py espefuse.py)"
83+
84+
zsh:
85+
86+
To activate completions in zsh, first make sure `compinit` is marked for
87+
autoload and run autoload:
88+
89+
.. code-block:: bash
90+
91+
autoload -U compinit
92+
compinit
93+
94+
Afterwards you can enable completions for esptool.py, espsecure.py and espefuse.py:
95+
96+
::
97+
98+
eval "$(register-python-argcomplete esptool.py espsecure.py espefuse.py)"
99+
100+
fish:
101+
102+
Not required to be in the config file, only run once
103+
104+
::
105+
106+
register-python-argcomplete --shell fish esptool.py espsecure.py espefuse.py >~/.config/fish/completions/esptool.py.fish
107+
108+
Other shells nor OS Windows are not supported.

espefuse/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
22
#
33
# SPDX-License-Identifier: GPL-2.0-or-later
4+
# PYTHON_ARGCOMPLETE_OK
45

56
import argparse
67
import os
@@ -285,6 +286,15 @@ def main(custom_commandline=None, esp=None):
285286

286287
efuse_operations.add_commands(subparsers, efuses)
287288

289+
# Enable argcomplete only on Unix-like systems
290+
if sys.platform != "win32":
291+
try:
292+
import argcomplete
293+
294+
argcomplete.autocomplete(parser)
295+
except ImportError:
296+
pass
297+
288298
grouped_remaining_args, used_cmds = split_on_groups(remaining_args)
289299
if len(grouped_remaining_args) == 0:
290300
parser.print_help()

espsecure/__init__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD
22
#
33
# SPDX-License-Identifier: GPL-2.0-or-later
4-
4+
# PYTHON_ARGCOMPLETE_OK
55
import argparse
66
import hashlib
77
import operator
@@ -1867,6 +1867,15 @@ def main(custom_commandline=None):
18671867
type=argparse.FileType("rb"),
18681868
)
18691869

1870+
# Enable argcomplete only on Unix-like systems
1871+
if sys.platform != "win32":
1872+
try:
1873+
import argcomplete
1874+
1875+
argcomplete.autocomplete(parser)
1876+
except ImportError:
1877+
pass
1878+
18701879
args = parser.parse_args(custom_commandline)
18711880
print("espsecure.py v%s" % esptool.__version__)
18721881
if args.operation is None:

esptool/__init__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Espressif Systems (Shanghai) CO LTD, other contributors as noted.
33
#
44
# SPDX-License-Identifier: GPL-2.0-or-later
5-
5+
# PYTHON_ARGCOMPLETE_OK
66
__all__ = [
77
"chip_id",
88
"detect_chip",
@@ -690,6 +690,15 @@ def add_spi_flash_subparsers(
690690
for operation in subparsers.choices.keys():
691691
assert operation in globals(), "%s should be a module function" % operation
692692

693+
# Enable argcomplete only on Unix-like systems
694+
if sys.platform != "win32":
695+
try:
696+
import argcomplete
697+
698+
argcomplete.autocomplete(parser)
699+
except ImportError:
700+
pass
701+
693702
argv = expand_file_arguments(argv or sys.argv[1:])
694703

695704
args = parser.parse_args(argv)

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"reedsolo>=1.5.3,<1.8",
4141
"PyYAML>=5.1",
4242
"intelhex",
43+
'argcomplete>=3; sys_platform != "win32"',
4344
]
4445

4546
[project.urls]

0 commit comments

Comments
 (0)