Browse code

Add zsh completion for 'docker swarm' commands

Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>

Steve Durrheimer authored on 2016/07/03 08:09:16
Showing 1 changed files
... ...
@@ -848,6 +848,74 @@ __docker_node_subcommand() {
848 848
 
849 849
 # EO node
850 850
 
851
+# BO swarm
852
+
853
+__docker_swarm_commands() {
854
+    local -a _docker_swarm_subcommands
855
+    _docker_swarm_subcommands=(
856
+        "init:Initialize a Swarm"
857
+        "inspect:Inspect the Swarm"
858
+        "join:Join a Swarm as a node and/or manager"
859
+        "leave:Leave a Swarm"
860
+        "update:Update the Swarm"
861
+    )
862
+    _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands
863
+}
864
+
865
+__docker_swarm_subcommand() {
866
+    local -a _command_args opts_help
867
+    local expl help="--help"
868
+    integer ret=1
869
+
870
+    opts_help=("(: -)--help[Print usage]")
871
+
872
+    case "$words[1]" in
873
+        (init)
874
+            _arguments $(__docker_arguments) \
875
+                $opts_help \
876
+                "($help)--auto-accept=[Acceptance policy]:policy:(manager none worker)" \
877
+                "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \
878
+                "($help)--force-new-cluster[Force create a new cluster from current state]" \
879
+                "($help)--listen-addr[Listen address]:ip\:port: " \
880
+                "($help)--secret[Set secret value needed to accept nodes into cluster]:secret: " && ret=0
881
+            ;;
882
+        (inspect)
883
+            _arguments $(__docker_arguments) \
884
+                $opts_help \
885
+                "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0
886
+            ;;
887
+        (join)
888
+            _arguments $(__docker_arguments) \
889
+                $opts_help \
890
+                "($help)--ca-hash=[Hash of the Root Certificate Authority certificate used for trusted join]:hash: " \
891
+                "($help)--listen-addr[Listen address]:ip\:port: " \
892
+                "($help)--manager[Try joining as a manager]" \
893
+                "($help)--secret[Secret for node acceptance]:secret: " \
894
+                "($help -):host\:port: " && ret=0
895
+            ;;
896
+        (leave)
897
+            _arguments $(__docker_arguments) \
898
+                $opts_help && ret=0
899
+            ;;
900
+        (update)
901
+            _arguments $(__docker_arguments) \
902
+                $opts_help \
903
+                "($help)--auto-accept=[Acceptance policy]:policy:(manager none worker)" \
904
+                "($help)--cert-expiry=[Validity period for node certificates]:duration: " \
905
+                "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \
906
+                "($help)--secret[Set secret value needed to accept nodes into cluster]:secret: " \
907
+                "($help)--task-history-limit[Task history retention limit]:limit: " && ret=0
908
+            ;;
909
+        (help)
910
+            _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
911
+            ;;
912
+    esac
913
+
914
+    return ret
915
+}
916
+
917
+# EO swarm
918
+
851 919
 __docker_volume_complete_ls_filters() {
852 920
     [[ $PREFIX = -* ]] && return 1
853 921
     integer ret=1
... ...
@@ -1547,6 +1615,23 @@ __docker_subcommand() {
1547 1547
                 "($help)--no-stream[Disable streaming stats and only pull the first result]" \
1548 1548
                 "($help -)*:containers:__docker_runningcontainers" && ret=0
1549 1549
             ;;
1550
+        (swarm)
1551
+            local curcontext="$curcontext" state
1552
+            _arguments $(__docker_arguments) \
1553
+                $opts_help \
1554
+                "($help -): :->command" \
1555
+                "($help -)*:: :->option-or-argument" && ret=0
1556
+
1557
+            case $state in
1558
+                (command)
1559
+                    __docker_swarm_commands && ret=0
1560
+                    ;;
1561
+                (option-or-argument)
1562
+                    curcontext=${curcontext%:*:*}:docker-${words[-1]}:
1563
+                    __docker_swarm_subcommand && ret=0
1564
+                    ;;
1565
+            esac
1566
+            ;;
1550 1567
         (tag)
1551 1568
             _arguments $(__docker_arguments) \
1552 1569
                 $opts_help \