From 07605cb3e0a3aca8963401c8f7a8e7ee42dbc399 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 12 Aug 2024 11:18:34 +0900 Subject: [PATCH] fix(update-alternatives): fix the "--help" parsing The format of `update-alternatives --help` and `alternative --help` is not in the form expected by `_comp_compgen_help`. This adjusts the output of `"$1" --help` before passing the output to `_comp_compgen_help`. --- completions/update-alternatives | 7 ++++++- test/t/test_update_alternatives.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/completions/update-alternatives b/completions/update-alternatives index 0d678fcc82a..b6f52830931 100644 --- a/completions/update-alternatives +++ b/completions/update-alternatives @@ -83,7 +83,12 @@ _comp_cmd_update_alternatives() _comp_cmd_update_alternatives__installed ;; *) - _comp_compgen_help + _comp_compgen_help - <<<"$(LANG=C "$1" --help 2>&1 | command sed ' + /usage:/,/^[[:space:]]*$/{ + s/^\([[:space:]]*usage:\)\{0,1\}[[:space:]]*[^[:space:]]*alternatives / / + s/^[[:space:]]*\[\(-.*\)\]/ \1/ + } + /common options:/,$s/ --/\n --/g')" ;; esac } && diff --git a/test/t/test_update_alternatives.py b/test/t/test_update_alternatives.py index 7c77730744f..16d63e295b1 100644 --- a/test/t/test_update_alternatives.py +++ b/test/t/test_update_alternatives.py @@ -6,3 +6,7 @@ class TestUpdateAlternatives: @pytest.mark.complete("update-alternatives --", require_cmd=True) def test_1(self, completion): assert completion + + @pytest.mark.complete("update-alternatives --", require_cmd=True) + def test_2(self, bash, completion): + assert all(x in completion for x in ["--list", "--remove"])