1#compdef nanoc
2# ------------------------------------------------------------------------------
3# Copyright (c) 2020 OKURA Masafumi, MIT License
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22# ------------------------------------------------------------------------------
23# Description
24# -----------
25#
26#  Completion script for nanoc (https://nanoc.ws/)
27#
28# ------------------------------------------------------------------------------
29# Authors
30# -------
31#
32#  * OKURA Masafumi (https://okuramasafumi.com)
33#
34#  This works is heavily inspired by the middleman completion by
35#  Jozef Izso (https://github.com/jozefizso)
36#
37# ------------------------------------------------------------------------------
38
39local ret=1 state
40
41local -a common_ops
42common_ops=(
43  {-C,--no-color}"[disable color]"
44  {-V,--verbose}"[make output more detailed]"
45  {-d,--debug}"[enable debugging]"
46  {-e,--env=}"[set environment]"
47  {-h,--help}"[show the help message and quit]"
48  {-l,--color}"[enable color]"
49  {-v,--version}"[show version information and quit]"
50  {-w,--warn}"[enable warnings]"
51)
52
53typeset -A opt_args
54_arguments \
55  ':subcommand:->subcommand' \
56  $common_ops \
57  '*::options:->options' && ret=0
58
59case $state in
60  subcommand)
61    local -a subcommands
62    subcommands=(
63      "check:run issue checks"
64      "compile:compile items of this site"
65      "create-site:create a site"
66      "deploy:deploy the compiled site"
67      "help:show help"
68      "prune:remove files not managed by Nanoc from the output directory"
69      "shell:open a shell on the Nanoc environment"
70      "show-data:show data in this site"
71      "show-plugins:show all available plugins"
72      "show-rules:describe the rules for each item"
73      "view:start the web server that serves static files"
74    )
75
76    _describe -t subcommands 'nanoc subcommand' subcommands && ret=0
77  ;;
78
79  options)
80    local -a args
81    args=(
82      $common_ops
83    )
84
85    local -a help
86    help=(
87      "--help[Display help information]"
88    )
89
90    case $words[1] in
91      check)
92        args=(
93          {-L,--list}"[list all checks]"
94          {-a,--all}"[run all checks]"
95        )
96      ;;
97
98      compile)
99        args=(
100          "--diff[generate diff]"
101          )
102      ;;
103
104      create-site)
105        args=(
106          "--force[force creation of new site]"
107          )
108      ;;
109
110      deploy)
111        args=(
112          {-C,--no-check}"[do not run the issue checks marked for deployment]"
113          {-D,--list-deployers}"[list available deployers]"
114          {-L,--list}"[list available locations to deploy to]"
115          {-n,--dry-run}"[show what would be deployed]"
116          {-t,--target=}"[specify the location to deploy to (default:\`default\`)]"
117          )
118      ;;
119
120      prune)
121        args=(
122          {-n,--dry-run}"[print files to be deleted instead of actually deleting them]"
123          {-y,--yes}"[confirm deletion]"
124          )
125      ;;
126
127      shell)
128        args=(
129          {-p,--preprocess}"[run preprocessor]"
130          )
131      ;;
132
133      show-data)
134        args=(
135          )
136      ;;
137
138      show-plugins)
139        args=(
140          )
141      ;;
142
143      show-rules)
144        args=(
145          )
146      ;;
147
148      view)
149        args=(
150          {-H,--handler=}"[specify the handler to use(webrick/mongrel/...)]"
151          {-L,--live-reload}"[reload on changes]"
152          {-o,--host=}"[specify the host to listen on(default: 127.0.0.1)]"
153          {-p,--port=}"[specify the port to listen on(default: 3000)]"
154          )
155      ;;
156    esac
157
158    _arguments $args && ret=0
159  ;;
160esac
161
162return ret
163