Skip to content

Commit 6722aaa

Browse files
committed
carton: new completion
1 parent f5d99f2 commit 6722aaa

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

completions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bashcomp_DATA = 2to3 \
3737
_cal \
3838
cancel \
3939
cardctl \
40+
carton \
4041
ccache \
4142
ccze \
4243
cfagent \

completions/carton

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# carton(3pm) completion -*- shell-script -*-
2+
3+
_carton_commands()
4+
{
5+
local cmds=$("${1:-carton}" usage 2>&1 | \
6+
command sed -ne '/.*command.* is one of/{n;p;q}')
7+
COMPREPLY+=( $(IFS="$IFS," compgen -W "$cmds" -- "$cur") )
8+
}
9+
10+
_carton_command_help()
11+
{
12+
local help=$(PERLDOC_PAGER=cat PERLDOC=-otext "${1:-carton}" -h $2 2>&1)
13+
COMPREPLY+=( $(compgen -W '$help' -- "$cur") )
14+
}
15+
16+
_carton()
17+
{
18+
local cur prev words cword split
19+
_init_completion -s || return
20+
21+
local i command
22+
for (( i=1; i < cword; i++ )); do
23+
case ${words[i]} in
24+
-*) ;;
25+
*) command=${words[i]}; break ;;
26+
esac
27+
done
28+
29+
if [[ -z "$command" ]]; then
30+
_carton_commands "$1"
31+
return
32+
fi
33+
34+
case $prev in
35+
--version|-v)
36+
return
37+
;;
38+
--help|-h)
39+
[[ -n "$command" ]] || _carton_commands "$1"
40+
return
41+
;;
42+
--cpanfile)
43+
if [[ $command == install ]]; then
44+
_filedir
45+
return
46+
fi
47+
;;
48+
--path)
49+
if [[ $command == install ]]; then
50+
_filedir -d
51+
return
52+
fi
53+
;;
54+
--without)
55+
if [[ $command == install ]]; then
56+
local phases="configure build test runtime develop"
57+
COMPREPLY+=( $(compgen -W '$phases' -- "$cur") )
58+
return
59+
fi
60+
;;
61+
esac
62+
63+
$split && return
64+
65+
if [[ $cur == -* ]]; then
66+
[[ $command == @(help|usage) ]] || COMPREPLY=(--help)
67+
_carton_command_help "$1" $command
68+
fi
69+
70+
case $command in
71+
show|update)
72+
: # TODO modules completion
73+
;;
74+
esac
75+
} &&
76+
complete -F _carton carton
77+
78+
# ex: filetype=sh

test/t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ EXTRA_DIST = \
5454
test_cal.py \
5555
test_cancel.py \
5656
test_cardctl.py \
57+
test_carton.py \
5758
test_cat.py \
5859
test_cc.py \
5960
test_ccache.py \

test/t/test_carton.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
4+
class TestCarton:
5+
@pytest.mark.complete("carton ", require_cmd=True)
6+
def test_commands(self, completion):
7+
assert all(x in completion for x in "help install".split())
8+
9+
@pytest.mark.complete("carton install -", require_cmd=True)
10+
def test_install_options(self, completion):
11+
assert all(x in completion for x in "--cached --help".split())

0 commit comments

Comments
 (0)