Skip to content

Commit e3e69c4

Browse files
authored
Cleaner compinit for zsh (#107)
1 parent f3f95c4 commit e3e69c4

2 files changed

Lines changed: 83 additions & 41 deletions

File tree

utils/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# A sample Makefile to use Dhall replica tests in your project.
2+
13
# with this rule if x.dhall exists but not x.json, and x.json is a target
4+
# x.json will be created
25
.dhall.json:
36
dhall-to-json --file $? --output $@
47

utils/_replica

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#compdef replica
22
typeset -A opt_args
33

4-
# local -a sub
5-
# sub=('info:get information about test suites' 'run:run test suite' 'new:create a test suite' 'help:get some help' 'version:show replica version' 'config:set replica default config')
6-
# _describe 'command' sub
7-
84
_arguments -C \
95
'1:command:->cmds' \
106
'*:: :->args' \
@@ -21,65 +17,111 @@ commands=(
2117
'version:show replica version'
2218
)
2319

24-
common=(
25-
'(-N --exclude)'{-n,--only}'[tests to run]:comma separated list' \
26-
'(-n --only)'{-N,--exclude}'[tests to exclude]:comma separated list' \
27-
{-t,-tags,--only-tags}'[tags to run]:comma separated list' \
28-
{-T,--exclude-tags}'[tags to include]:comma separated list' \
29-
{--last-fails,-l}'[select only failing tests]' \
30-
'(-v --verbose)--log[log level]:log:(none critical warning info debug)' \
31-
{-v,--verbose}'[verbose output (log info)]'
32-
'--replica-dir[replica store directory]:replica dir:_files -/' \
33-
'--golden-dir[golden values directory]:golden dir:_files -/' \
34-
'(--no-color --no-colour)'{--color,--colour,-c}'[use coloured ouput]' \
35-
'(--color --colour -c)'{--no-color,--no-colour}'[desactivate coloured ouput]' \
36-
'(--ascii)--utf8[use emojis in reports]' \
37-
"(--utf8)--ascii[reports don't use emojis]" \
38-
'(--diff)--no-diff[dont show diff on errors]' \
39-
'(--no-diff)--diff[define a diff command]:either a known or a custom command:(git diff native)'
20+
tests=(
21+
{-n,--only}'[list tests to run]:tests:_testnames'
22+
{-N,--exclude}'[tests to ignore]:tests:_testnames'
23+
)
24+
25+
suites=(
26+
+ '(suites)'
27+
{-s,--suites,--only-suites}'[suites to run]:suites:_suitenames'
28+
{-S,--exclude-suites}'[suites to exclude]:suites:_suitesnames'
29+
)
30+
31+
tags=(
32+
+ '(tags)'
33+
{-t,--tags}'[tags to run]:tags:_tagnames'
34+
{-T,--exclude-tags}'[tags to exclude]:tags:_tagnames'
4035
)
4136

37+
common=(
38+
$tests
39+
{-l,--last-fails}'[select only failing tests]'
40+
'--replica-dir[replica store directory]:replica_dir:_path_files -/'
41+
'--golden-dir[golden values directory]:golden_dir:_path_files -/'
42+
$suites
43+
$tags
44+
+ '(show_diff)'
45+
'--no-diff[dont show diff on errors]'
46+
{-d,--diff}'[define a diff command]'
47+
+ '(symbols)'
48+
'--ascii[disable emojis in reports]'
49+
'--utf8[enable emojis in reports]'
50+
+ '(termcolor)'
51+
{--no-color,--no-colour}'[disable coloured ouput]'
52+
{-color,--colour}'[enable coloured ouput]'
53+
+ '(verbosity)'
54+
{-v,--verbose}'[similar to log info]'
55+
'--log[log level]:log_level:(none debug info warning critical)'
56+
)
57+
58+
_testnames() {
59+
if command -v jq
60+
then
61+
_values -s , 'flags' `jq -Scrs ".[] | keys | .[]" *.json`
62+
fi
63+
}
64+
65+
_tagnames() {
66+
if (command -v jq > /dev/null)
67+
then
68+
_values -s , 'flags' `jq -crs ".[] | .[] | .tags | .[]" *.json | sort -u`
69+
fi
70+
}
71+
72+
_suitenames() {
73+
if (command -v jq > /dev/null)
74+
then
75+
_values -s , 'flags' `jq -crs ".[] | .[] | .suite" *.json | sort -u`
76+
fi
77+
}
78+
4279
case "$state" in
43-
(cmds)
44-
_describe -V -t commands 'command' commands && ret=0
80+
cmds)
81+
_describe -V -t commands 'command' commands \
82+
&& ret=0
4583
;;
46-
(args)
84+
args)
4785
case $line[1] in
48-
(info)
86+
info)
4987
_arguments \
5088
{-e,--expectations}'[show expectations for each test]' \
5189
$common \
52-
'(-)*:tests files:_files' \
90+
'(-)*:tests files:_path_files -g "*.json' \
5391
&& ret=0
5492
;;
55-
(run)
93+
run)
5694
_arguments \
5795
{--threads,-x}'[Number of threads to run the tests]' \
5896
{--punitive,-p}'[Stop on first error]' \
97+
{--interactive,-i}'[Generate golden value if different/missing]' \
98+
{--hide-success,--fail-only}'[Only show failing tests]' \
5999
$common \
60-
'(-)*:tests files:_files -g *.json' \
100+
+ '(timing)' \
101+
{--timing,--duration,-d}'[display execution time of each tests]' \
102+
{--no-timing,--no-duration,-D}'[hide execution time of each tests]' \
103+
'(-)*:tests files:_path_files -g "*.json" -/' \
61104
&& ret=0
62105
;;
63-
(new)
106+
new)
64107
_arguments \
65108
'--format[type of the file to be created]:file format:(json dhall)' \
66-
+ sample \
67-
'(noSample)'{-s,--includeSample}'[sample test included]:sample' \
68-
+ noSample \
69-
'(sample)'{-S,--noSample}'[no sample test included]:no sample' \
70-
'(-):created file:_files' \
109+
+ '(use_sample)' \
110+
{-s,--includeSample}'[sample test included]:sample' \
111+
{-S,--noSample}'[no sample test included]:no sample' \
71112
&& ret=0
72113
;;
73-
(set)
114+
set)
74115
_arguments \
116+
+ '(scope)'
75117
'*'{-l,--local}'[Set local config value]:key=value pair:->kv' \
76118
'*'{-g,--global}'[Set global config value]:key=value pair:->kv' \
77119
&& ret=0
78120
case "$state" in
79-
(kv)
121+
kv)
80122
_values 'replica configuration' \
81-
'replicaDir:replica file location:_files' \
82-
'goldenDir:golden values location:_files' \
123+
'replicaDir:replica file location:_path_files -/' \
124+
'goldenDir:golden values location:_path_files -/' \
83125
'colour:coloured output:(true false)' \
84126
'ascii:use only ascii in reports:(false true)' \
85127
'diff:tool used to print diff' \
@@ -88,16 +130,13 @@ case "$state" in
88130
&& ret=0
89131
esac
90132
;;
91-
(help)
133+
help)
92134
_arguments -C ':topic:->topic'
93135
case "$state" in
94136
(topic)
95137
_describe -V -t topic 'topic' commands && ret=0
96138
esac
97139
;;
98-
(version)
99-
ret=0
100-
;;
101140
esac
102141
;;
103142
esac

0 commit comments

Comments
 (0)