From 4ef2e284969cffe756727e85c961ce247b7f9ca5 Mon Sep 17 00:00:00 2001 From: Patrick ZAJDA Date: Sun, 5 Nov 2023 21:27:14 +0100 Subject: [PATCH] Add basic shell autocompletion using argcomplete (#5618) --- esphome/__main__.py | 4 ++++ requirements.txt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/esphome/__main__.py b/esphome/__main__.py index cf540f58ba..a253fc78a0 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -1,3 +1,4 @@ +# PYTHON_ARGCOMPLETE_OK import argparse import functools import logging @@ -7,6 +8,8 @@ import sys import time from datetime import datetime +import argcomplete + from esphome import const, writer, yaml_util import esphome.codegen as cg from esphome.config import iter_components, read_config, strip_default_ids @@ -966,6 +969,7 @@ def parse_args(argv): # Finally, run the new-style parser again with the possibly swapped arguments, # and let it error out if the command is unparsable. parser.set_defaults(deprecated_argv_suggestion=deprecated_argv_suggestion) + argcomplete.autocomplete(parser) return parser.parse_args(arguments) diff --git a/requirements.txt b/requirements.txt index b9b6708ff2..5c57f3e933 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,6 @@ kconfiglib==13.7.1 # esp-idf >= 5.0 requires this pyparsing >= 3.0 + +# For autocompletion +argcomplete>=2.0.0