diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index abf8afe4..40b46907 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -5,13 +5,21 @@ # later we can have a separate changelist to refactor main.py into smaller files # pylint: disable=too-many-lines +from typing import List, Optional, Union +from types import ModuleType + import argparse +argcomplete: Union[None, ModuleType] = None +try: + import argcomplete +except ImportError as e: + pass # already set to None by default above + import logging import os import platform import sys import time -from typing import List, Optional try: import pyqrcode # type: ignore[import-untyped] @@ -1961,6 +1969,8 @@ def initParser(): parser.set_defaults(deprecated=None) + if argcomplete is not None: + argcomplete.autocomplete(parser) args = parser.parse_args() mt_config.args = args mt_config.parser = parser diff --git a/poetry.lock b/poetry.lock index d4b8cd3c..90af31b6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -44,6 +44,20 @@ files = [ {file = "appnope-0.1.4.tar.gz", hash = "sha256:1de3860566df9caf38f01f86f65e0e13e379af54f9e4bee1e66b48f2efffd1ee"}, ] +[[package]] +name = "argcomplete" +version = "3.5.2" +description = "Bash tab completion for argparse" +optional = true +python-versions = ">=3.8" +files = [ + {file = "argcomplete-3.5.2-py3-none-any.whl", hash = "sha256:036d020d79048a5d525bc63880d7a4b8d1668566b8a76daf1144c0bbe0f63472"}, + {file = "argcomplete-3.5.2.tar.gz", hash = "sha256:23146ed7ac4403b70bd6026402468942ceba34a6732255b9edf5b7354f68a6bb"}, +] + +[package.extras] +test = ["coverage", "mypy", "pexpect", "ruff", "wheel"] + [[package]] name = "argon2-cffi" version = "23.1.0" @@ -4332,10 +4346,10 @@ type = ["pytest-mypy"] [extras] analysis = ["dash", "dash-bootstrap-components", "pandas", "pandas-stubs"] -cli = ["dotmap", "print-color", "pyqrcode"] +cli = ["argcomplete", "dotmap", "print-color", "pyqrcode"] tunnel = ["pytap2"] [metadata] lock-version = "2.0" python-versions = "^3.9,<3.14" -content-hash = "fa490a41df9742f691c43a4915f7751b6adbded7605c3f0936f74681c1da5244" +content-hash = "4ab787ea28390a4e19c2dfbfdee920174146b144a63fa1e138e25b7120941490" diff --git a/pyproject.toml b/pyproject.toml index 500a6650..d1636961 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ pyyaml = "^6.0.1" pypubsub = "^4.0.3" bleak = "^0.22.3" packaging = "^24.0" +argcomplete = { version = "^3.5.2", optional = true } pyqrcode = { version = "^1.2.1", optional = true } dotmap = { version = "^1.3.30", optional = true } print-color = { version = "^0.4.6", optional = true } @@ -64,7 +65,7 @@ ipywidgets = "^8.1.3" jupyterlab-widgets = "^3.0.11" [tool.poetry.extras] -cli = ["pyqrcode", "print-color", "dotmap"] +cli = ["pyqrcode", "print-color", "dotmap", "argcomplete"] tunnel = ["pytap2"] analysis = ["dash", "dash-bootstrap-components", "pandas", "pandas-stubs"]