_tugboat 2.83 KB
Newer Older
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
#compdef tugboat
#autoload

# Tugboat zsh autocompletion


local -a _commands
_commands=(
  'add-key:[NAME] Upload an ssh public key.'
  'authorize:Authorize a DigitalOcean account with tugboat.'
  'create:[NAME] Create a droplet.'
  'destroy:[FUZZY_NAME] Destroy a droplet.'
  'destroy_image:[FUZZY_NAME] Destroy an image.'
  'droplets:Retrieve a list of your droplets.'
  'halt:[FUZZY_NAME] Shutdown a droplet.'
  'help:[COMMAND] Describe commands or a specific command.'
  'images:Retrieve a list of your images.'
  'info:[FUZZY_NAME] [OPTIONS] Show a droplets information.'
  'info_image:[FUZZY_NAME] [OPTIONS] Show an images information.'
  'keys:Show available SSH keys.'
  'password-reset:[FUZZY_NAME] Reset root password.'
  'rebuild:[FUZZY_NAME] [IMAGE_NAME] Rebuild a droplet.'
  'regions:Show regions.'
  'resize:[FUZZY_NAME -s, --size=N] Resize a droplet.'
  'restart:[FUZZY_NAME] Restart a droplet.'
  'sizes:Show available droplet sizes.'
  'snapshot:[SNAPSHOT_NAME] [FUZZY_NAME] [OPTIONS] Queue a snapshot of the droplet.'
  'ssh:[FUZZY_NAME] SSH into a droplet.'
  'start:[FUZZY_NAME] Start a droplet.'
  'verify:Check your DigitalOcean credentials.'
  'version:Show version.'
  'wait:[FUZZY_NAME] Wait for a droplet to reach a state.'
)

local -a _create_arguments
_create_arguments=(
  '-s:[--size=N] The size_id of the droplet'
  '-i:[--image=N] The image_id of the droplet'
  '-r:[--region=N] The region_id of the droplet'
  '-k:[--keys=KEYS] A comma separated list of SSH key ids to add to the droplet'
  '-p:[--private-networking] Enable private networking on the droplet'
  '-b:[--backups-enabled] Enable backups on the droplet'
  '-q:[--quiet]'
)

__task_list ()
{
  local expl
  declare -a tasks

  arguments=(add-key authorize create destroy destroy_image droplets halt help images info info_image keys password-reset rebuild regions resize restart sizes snapshot ssh start verify version wait)

  _wanted tasks expl 'help' compadd $arguments
}

__droplets_list ()
{
    _wanted application expl 'command' compadd $(command tugboat droplets | cut -d " " -f1)
}

__tugboat-create ()
{
    local curcontext="$curcontext" state line
    typeset -A opt_args

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

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

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

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

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

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

      (ssh)
        _arguments ':feature:__droplets_list'
      ;;

      (create)
        _arguments ':feature:__tugboat-create'
      ;;
    esac
  ;;
esac