diff --git a/README.md b/README.md index 4fa348f431..61d36acdd0 100755 --- a/README.md +++ b/README.md @@ -134,6 +134,17 @@ For additional details, see the [ROCm Contributing Guide](https://rocm.docs.amd. * python 3.7+ 64-bit * amdgpu driver must be loaded for amdsmi_init() to pass +### Optional autocompletion + +`amd-smi` cli application supports autocompletion. It is enabled by using the +following commands: + +```bash +python3 -m pip install argcomplete +activate-global-python-argcomplete +# restart shell to enable +``` + ### CLI Installation Before amd-smi install, ensure previous versions of amdsmi library are uninstalled using pip: diff --git a/amdsmi_cli/amdsmi_cli.py b/amdsmi_cli/amdsmi_cli.py index 3a88ae5acc..3bafe179ca 100755 --- a/amdsmi_cli/amdsmi_cli.py +++ b/amdsmi_cli/amdsmi_cli.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK + # # Copyright (C) 2023 Advanced Micro Devices. All rights reserved. # @@ -23,6 +25,11 @@ import logging import sys +try: + import argcomplete +except ImportError: + logging.debug("argcomplete module not found. Autocomplete will not work.") + from amdsmi_commands import AMDSMICommands from amdsmi_parser import AMDSMIParser from amdsmi_logger import AMDSMILogger @@ -63,6 +70,11 @@ if __name__ == "__main__": amd_smi_commands.reset, amd_smi_commands.rocm_smi) try: + try: + argcomplete.autocomplete(amd_smi_parser) + except NameError: + logging.debug("argcomplete module not found. Autocomplete will not work.") + args = amd_smi_parser.parse_args(args=None if sys.argv[1:] else ['--help']) # Handle command modifiers before subcommand execution