aboutsummaryrefslogtreecommitdiffstats
path: root/src/_fleetctl
blob: 542d7cfa2b73dba0852cfaa6430a903b0b8822ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#compdef fleetctl
# ------------------------------------------------------------------------------
# Copyright (c) 2009-2015 Robby Russell and contributors (see
# https://github.com/ohmyzsh/ohmyzsh/graphs/contributors)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for fleetctl (https://github.com/coreos/fleet).
#
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Remi Paulmier (https://github.com/shtouff)
#
# ------------------------------------------------------------------------------

# fleetctl zsh completion

local -a _1st_arguments
_1st_arguments=(
    'cat:Output the contents of a submitted unit'
    'destroy:Destroy one or more units in the cluster'
    'fd-forward:Proxy stdin and stdout to a unix domain socket'
    'help:Show a list of commands or help for one command'
    'journal:Print the journal of a unit in the cluster to stdout'
    'list-machines:Enumerate the current hosts in the cluster'
    'list-unit-files:List the units that exist in the cluster.'
    'list-units:List the current state of units in the cluster'
    'load:Schedule one or more units in the cluster, first submitting them if necessary.'
    'ssh:Open interactive shell on a machine in the cluster'
    'start:Instruct systemd to start one or more units in the cluster, first submitting and loading if necessary.'
    'status:Output the status of one or more units in the cluster'
    'stop:Instruct systemd to stop one or more units in the cluster.'
    'submit:Upload one or more units to the cluster without starting them'
    'unload:Unschedule one or more units in the cluster.'
    'version:Print the version and exit'
)

__task_list ()
{
    local expl
    declare -a tasks

    tasks=(cat destroy fd-forward help journal list-machines list-unit-files \
      list-units load ssh start status stop submit unload version)

    _wanted tasks expl 'help' compadd $tasks
}

__unit_list ()
{
    _wanted application expl 'command' compadd $(command fleetctl list-units | \
      tail -n +2  | awk '{print $1}')
}

local expl

local curcontext="$curcontext" state line
local -A opt_args

_arguments -C \
    ':command:->command' \
    '*::options:->options'

case $state in
  (command)
      _describe -t commands "gem subcommand" _1st_arguments
      return
  ;;

  (options)
    case $line[1] in
      (help)
         _arguments ':feature:__task_list'
      ;;

      (destroy|journal|start|status|stop|unload|cat)
          _arguments '*:feature:__unit_list'
      ;;

      (load|submit)
          _arguments '*:file:_files -g *.service'
      ;;

      (ssh)
          _arguments '*:host:_hosts'
      ;;

      (*)
          _arguments '*:file:_files'
      ;;
    esac
  ;;
esac

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et