forked from espressif/esp-idf
Merge branch 'feature/idf_py_at_file_autocomplete' into 'master'
feat(tools): autocomplete @-arguments of idf.py with file names See merge request espressif/esp-idf!31081
This commit is contained in:
10
tools/idf.py
10
tools/idf.py
@ -13,6 +13,7 @@
|
|||||||
# any external libraries here - put in external script, or import in
|
# any external libraries here - put in external script, or import in
|
||||||
# their specific function instead.
|
# their specific function instead.
|
||||||
import codecs
|
import codecs
|
||||||
|
import glob
|
||||||
import json
|
import json
|
||||||
import locale
|
import locale
|
||||||
import os.path
|
import os.path
|
||||||
@ -142,6 +143,7 @@ def _safe_relpath(path: str, start: Optional[str]=None) -> str:
|
|||||||
def init_cli(verbose_output: Optional[List]=None) -> Any:
|
def init_cli(verbose_output: Optional[List]=None) -> Any:
|
||||||
# Click is imported here to run it after check_environment()
|
# Click is imported here to run it after check_environment()
|
||||||
import click
|
import click
|
||||||
|
from click.shell_completion import CompletionItem
|
||||||
|
|
||||||
class Deprecation(object):
|
class Deprecation(object):
|
||||||
"""Construct deprecation notice for help messages"""
|
"""Construct deprecation notice for help messages"""
|
||||||
@ -451,6 +453,14 @@ def init_cli(verbose_output: Optional[List]=None) -> Any:
|
|||||||
return Action(name=name, callback=callback.unwrapped_callback)
|
return Action(name=name, callback=callback.unwrapped_callback)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def shell_complete(self, ctx: click.core.Context, incomplete: str) -> List[CompletionItem]:
|
||||||
|
if incomplete.startswith('@'):
|
||||||
|
path_prefix = incomplete[1:]
|
||||||
|
candidates = glob.glob(path_prefix + '*')
|
||||||
|
result = [CompletionItem(f'@{c}') for c in candidates]
|
||||||
|
return result
|
||||||
|
return super(CLI, self).shell_complete(ctx, incomplete) # type: ignore
|
||||||
|
|
||||||
def _print_closing_message(self, args: PropertyDict, actions: KeysView) -> None:
|
def _print_closing_message(self, args: PropertyDict, actions: KeysView) -> None:
|
||||||
# print a closing message of some kind,
|
# print a closing message of some kind,
|
||||||
# except if any of the following actions were requested
|
# except if any of the following actions were requested
|
||||||
|
Reference in New Issue
Block a user