diff --git a/tools/idf.py b/tools/idf.py index 61eaf2bddd..14730df1e1 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -13,6 +13,7 @@ # any external libraries here - put in external script, or import in # their specific function instead. import codecs +import glob import json import locale 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: # Click is imported here to run it after check_environment() import click + from click.shell_completion import CompletionItem class Deprecation(object): """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 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: # print a closing message of some kind, # except if any of the following actions were requested