From b5d8665cb5d2fab81756d9637777630abeaff1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Omar=20Vergara=20P=C3=A9rez?= Date: Sat, 14 Nov 2020 15:32:58 -0600 Subject: [PATCH 1/3] feat(commitizen/cli): add the integration with argcomplete 137 --- commitizen/cli.py | 2 ++ pyproject.toml | 1 + 2 files changed, 3 insertions(+) diff --git a/commitizen/cli.py b/commitizen/cli.py index 2f847ef8c..45aa33f30 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -3,6 +3,7 @@ import sys from functools import partial +import argcomplete from decli import cli from commitizen import commands, config @@ -265,6 +266,7 @@ def main(): conf = config.read_cfg() parser = cli(data) + argcomplete.autocomplete(parser) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) diff --git a/pyproject.toml b/pyproject.toml index 39f09b3f6..9eadaf7fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,7 @@ packaging = ">=19,<21" tomlkit = "^0.5.3" jinja2 = "^2.10.3" pyyaml = ">=3.08" +argcomplete = "^1.12.1" [tool.poetry.dev-dependencies] ipython = "^7.2" From bf56194d97c6785377ca82aa9266fc8e6cce7fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Omar=20Vergara=20P=C3=A9rez?= Date: Sat, 14 Nov 2020 15:34:57 -0600 Subject: [PATCH 2/3] test(tests/test_cli): add a test function to test the activation of the auto-completion for cz 137 --- tests/test_cli.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7935806be..59627f9d9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,5 @@ import sys +import subprocess import pytest @@ -78,3 +79,16 @@ def test_commitizen_debug_excepthook(capsys): assert excinfo.type == SystemExit assert excinfo.value.code == NotAGitProjectError.exit_code assert "NotAGitProjectError" in str(excinfo.traceback[0]) + + +def test_argcomplete_activation(): + """ + This function is testing the one-time activation of argcomplete for + commitizen only. + + Equivalent to run: + $ eval "$(register-python-argcomplete pytest)" + """ + output = subprocess.run(["register-python-argcomplete", "cz"]) + + assert output.returncode == 0 From 61c13e451843b38e0980a563047e9a061670153a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Omar=20Vergara=20P=C3=A9rez?= Date: Sat, 14 Nov 2020 15:36:07 -0600 Subject: [PATCH 3/3] docs(docs/README): add the instructions to activate the auto-completion for cz in README.md 137 test(tests/test_cli): add a missing dependency 137 --- docs/README.md | 26 ++++++++++++++++++++++++++ tests/test_cli.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 4b8707712..77205dfc1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -144,6 +144,32 @@ commands: current project (default: installed commitizen) ``` +## Setting up bash completion + +When using bash as your shell (limited support for zsh, fish, and tcsh is available), Commitizen can use [argcomplete](https://kislyuk.github.io/argcomplete/) for auto-completion. For this argcomplete needs to be enabled. + +argcomplete is installed when you install Commitizen since it's a dependency. + +If Commitizen is installed globally, global activation can be executed: + +```bash +sudo activate-global-python-argcomplete +``` + +For permanent (but not global) Commitizen activation, use: + +```bash +register-python-argcomplete cz >> ~/.bashrc +``` + +For one-time activation of argcomplete for Commitizen only, use: + +```bash +eval "$(register-python-argcomplete cz)" +``` + +For further information on activation, please visit the [argcomplete website](https://kislyuk.github.io/argcomplete/). + ## Third-Party Commitizen Templates See [Third-Party Commitizen Templates](third-party-commitizen.md). diff --git a/tests/test_cli.py b/tests/test_cli.py index 59627f9d9..2b73bbd5c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,5 @@ -import sys import subprocess +import sys import pytest