Skip to content

Commit 07605cb

Browse files
akinomyogascop
authored andcommitted
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`.
1 parent b44b29c commit 07605cb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

completions/update-alternatives

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ _comp_cmd_update_alternatives()
8383
_comp_cmd_update_alternatives__installed
8484
;;
8585
*)
86-
_comp_compgen_help
86+
_comp_compgen_help - <<<"$(LANG=C "$1" --help 2>&1 | command sed '
87+
/usage:/,/^[[:space:]]*$/{
88+
s/^\([[:space:]]*usage:\)\{0,1\}[[:space:]]*[^[:space:]]*alternatives / /
89+
s/^[[:space:]]*\[\(-.*\)\]/ \1/
90+
}
91+
/common options:/,$s/ --/\n --/g')"
8792
;;
8893
esac
8994
} &&

test/t/test_update_alternatives.py

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ class TestUpdateAlternatives:
66
@pytest.mark.complete("update-alternatives --", require_cmd=True)
77
def test_1(self, completion):
88
assert completion
9+
10+
@pytest.mark.complete("update-alternatives --", require_cmd=True)
11+
def test_2(self, bash, completion):
12+
assert all(x in completion for x in ["--list", "--remove"])

0 commit comments

Comments
 (0)