Skip to content

Commit

Permalink
feat(slabtop): new completion
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Sep 16, 2024
1 parent 0eef733 commit d534d0b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ bashcomp_DATA = 2to3 \
sha256sum \
shellcheck \
sitecopy \
slabtop \
_slackpkg \
slapt-get \
slapt-src \
Expand Down
31 changes: 31 additions & 0 deletions completions/slabtop
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# bash completion for slabtop -*- shell-script -*-

_comp_cmd_slabtop()
{
local cur prev words cword comp_args
_comp_initialize -- "$@" || return

local noargopts='!(-*|*[ds]*)'
# shellcheck disable=SC2254
case $prev in
--help | --version | --delay | -${noargopts}[hVd])
return
;;
--sort | -${noargopts}s)
_comp_compgen_split -- "$(
"$1" --help | command sed \
-e '/^The following are valid sort criteria/,/^$/!d' \
-ne 's/^[[:space:]]\(.\):.*/\1/p'
)"
return
;;
esac

if [[ $cur == -* ]]; then
_comp_compgen_help
return
fi
} &&
complete -F _comp_cmd_slabtop slabtop

# ex: filetype=sh
1 change: 1 addition & 0 deletions test/t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ EXTRA_DIST = \
test_shar.py \
test_shellcheck.py \
test_sitecopy.py \
test_slabtop.py \
test_slackpkg.py \
test_slapt_get.py \
test_slapt_src.py \
Expand Down
11 changes: 11 additions & 0 deletions test/t/test_slabtop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


class TestSlabtop:
@pytest.mark.complete("slabtop --", require_cmd=True)
def test_basic(self, completion):
assert completion

@pytest.mark.complete("slabtop --sort ", require_cmd=True)
def test_sort_arg(self, completion):
assert completion
1 change: 1 addition & 0 deletions test/test-cmd-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ sha512sum
shar
shellcheck
sitecopy
slabtop
slapt-get
slapt-src
smartctl
Expand Down

0 comments on commit d534d0b

Please sign in to comment.