Skip to content

Commit

Permalink
fix(update-alternatives): fix the "--help" parsing
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
akinomyoga authored and scop committed Aug 12, 2024
1 parent b44b29c commit 07605cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion completions/update-alternatives
Original file line number Diff line number Diff line change
Expand Up @@ -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
} &&
Expand Down
4 changes: 4 additions & 0 deletions test/t/test_update_alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

0 comments on commit 07605cb

Please sign in to comment.