Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
(cherry picked from commit 1e0c612f848a3fa5bfbcf347e5f91512ae9c4773)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
| ... | ... |
@@ -1883,6 +1883,147 @@ __docker_service_subcommand() {
|
| 1883 | 1883 |
|
| 1884 | 1884 |
# EO service |
| 1885 | 1885 |
|
| 1886 |
+# BO stack |
|
| 1887 |
+ |
|
| 1888 |
+__docker_stack_complete_ps_filters() {
|
|
| 1889 |
+ [[ $PREFIX = -* ]] && return 1 |
|
| 1890 |
+ integer ret=1 |
|
| 1891 |
+ |
|
| 1892 |
+ if compset -P '*='; then |
|
| 1893 |
+ case "${${words[-1]%=*}#*=}" in
|
|
| 1894 |
+ (desired-state) |
|
| 1895 |
+ state_opts=('accepted' 'running')
|
|
| 1896 |
+ _describe -t state-opts "desired state options" state_opts && ret=0 |
|
| 1897 |
+ ;; |
|
| 1898 |
+ *) |
|
| 1899 |
+ _message 'value' && ret=0 |
|
| 1900 |
+ ;; |
|
| 1901 |
+ esac |
|
| 1902 |
+ else |
|
| 1903 |
+ opts=('desired-state' 'id' 'name')
|
|
| 1904 |
+ _describe -t filter-opts "filter options" opts -qS "=" && ret=0 |
|
| 1905 |
+ fi |
|
| 1906 |
+ |
|
| 1907 |
+ return ret |
|
| 1908 |
+} |
|
| 1909 |
+ |
|
| 1910 |
+__docker_stack_complete_services_filters() {
|
|
| 1911 |
+ [[ $PREFIX = -* ]] && return 1 |
|
| 1912 |
+ integer ret=1 |
|
| 1913 |
+ |
|
| 1914 |
+ if compset -P '*='; then |
|
| 1915 |
+ case "${${words[-1]%=*}#*=}" in
|
|
| 1916 |
+ *) |
|
| 1917 |
+ _message 'value' && ret=0 |
|
| 1918 |
+ ;; |
|
| 1919 |
+ esac |
|
| 1920 |
+ else |
|
| 1921 |
+ opts=('id' 'label' 'name')
|
|
| 1922 |
+ _describe -t filter-opts "filter options" opts -qS "=" && ret=0 |
|
| 1923 |
+ fi |
|
| 1924 |
+ |
|
| 1925 |
+ return ret |
|
| 1926 |
+} |
|
| 1927 |
+ |
|
| 1928 |
+__docker_stacks() {
|
|
| 1929 |
+ [[ $PREFIX = -* ]] && return 1 |
|
| 1930 |
+ integer ret=1 |
|
| 1931 |
+ local line s |
|
| 1932 |
+ declare -a lines stacks |
|
| 1933 |
+ |
|
| 1934 |
+ lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}})
|
|
| 1935 |
+ |
|
| 1936 |
+ # Parse header line to find columns |
|
| 1937 |
+ local i=1 j=1 k header=${lines[1]}
|
|
| 1938 |
+ declare -A begin end |
|
| 1939 |
+ while (( j < ${#header} - 1 )); do
|
|
| 1940 |
+ i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
|
|
| 1941 |
+ j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
|
|
| 1942 |
+ k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
|
|
| 1943 |
+ begin[${header[$i,$((j-1))]}]=$i
|
|
| 1944 |
+ end[${header[$i,$((j-1))]}]=$k
|
|
| 1945 |
+ done |
|
| 1946 |
+ end[${header[$i,$((j-1))]}]=-1
|
|
| 1947 |
+ lines=(${lines[2,-1]})
|
|
| 1948 |
+ |
|
| 1949 |
+ # Service ID |
|
| 1950 |
+ for line in $lines; do |
|
| 1951 |
+ s="${line[${begin[ID]},${end[ID]}]%% ##}"
|
|
| 1952 |
+ stacks=($stacks $s) |
|
| 1953 |
+ done |
|
| 1954 |
+ |
|
| 1955 |
+ _describe -t stacks-list "stacks" stacks "$@" && ret=0 |
|
| 1956 |
+ return ret |
|
| 1957 |
+} |
|
| 1958 |
+ |
|
| 1959 |
+__docker_complete_stacks() {
|
|
| 1960 |
+ [[ $PREFIX = -* ]] && return 1 |
|
| 1961 |
+ __docker_stacks "$@" |
|
| 1962 |
+} |
|
| 1963 |
+ |
|
| 1964 |
+__docker_stack_commands() {
|
|
| 1965 |
+ local -a _docker_stack_subcommands |
|
| 1966 |
+ _docker_stack_subcommands=( |
|
| 1967 |
+ "deploy:Deploy a new stack or update an existing stack" |
|
| 1968 |
+ "ls:List stacks" |
|
| 1969 |
+ "ps:List the tasks in the stack" |
|
| 1970 |
+ "rm:Remove the stack" |
|
| 1971 |
+ "services:List the services in the stack" |
|
| 1972 |
+ ) |
|
| 1973 |
+ _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands |
|
| 1974 |
+} |
|
| 1975 |
+ |
|
| 1976 |
+__docker_stack_subcommand() {
|
|
| 1977 |
+ local -a _command_args opts_help |
|
| 1978 |
+ local expl help="--help" |
|
| 1979 |
+ integer ret=1 |
|
| 1980 |
+ |
|
| 1981 |
+ opts_help=("(: -)--help[Print usage]")
|
|
| 1982 |
+ |
|
| 1983 |
+ case "$words[1]" in |
|
| 1984 |
+ (deploy|up) |
|
| 1985 |
+ _arguments $(__docker_arguments) \ |
|
| 1986 |
+ $opts_help \ |
|
| 1987 |
+ "($help)--bundle-file=[Path to a Distributed Application Bundle file]:dab:_files -g \"*.dab\"" \ |
|
| 1988 |
+ "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file]:compose file:_files -g \"*.(yml|yaml)\"" \
|
|
| 1989 |
+ "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ |
|
| 1990 |
+ "($help -):stack:__docker_complete_stacks" && ret=0 |
|
| 1991 |
+ ;; |
|
| 1992 |
+ (ls|list) |
|
| 1993 |
+ _arguments $(__docker_arguments) \ |
|
| 1994 |
+ $opts_help && ret=0 |
|
| 1995 |
+ ;; |
|
| 1996 |
+ (ps) |
|
| 1997 |
+ _arguments $(__docker_arguments) \ |
|
| 1998 |
+ $opts_help \ |
|
| 1999 |
+ "($help -a --all)"{-a,--all}"[Display all tasks]" \
|
|
| 2000 |
+ "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \
|
|
| 2001 |
+ "($help)--no-resolve[Do not map IDs to Names]" \ |
|
| 2002 |
+ "($help)--no-trunc[Do not truncate output]" \ |
|
| 2003 |
+ "($help -):stack:__docker_complete_stacks" && ret=0 |
|
| 2004 |
+ ;; |
|
| 2005 |
+ (rm|remove|down) |
|
| 2006 |
+ _arguments $(__docker_arguments) \ |
|
| 2007 |
+ $opts_help \ |
|
| 2008 |
+ "($help -):stack:__docker_complete_stacks" && ret=0 |
|
| 2009 |
+ ;; |
|
| 2010 |
+ (services) |
|
| 2011 |
+ _arguments $(__docker_arguments) \ |
|
| 2012 |
+ $opts_help \ |
|
| 2013 |
+ "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \
|
|
| 2014 |
+ "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \
|
|
| 2015 |
+ "($help -):stack:__docker_complete_stacks" && ret=0 |
|
| 2016 |
+ ;; |
|
| 2017 |
+ (help) |
|
| 2018 |
+ _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 |
|
| 2019 |
+ ;; |
|
| 2020 |
+ esac |
|
| 2021 |
+ |
|
| 2022 |
+ return ret |
|
| 2023 |
+} |
|
| 2024 |
+ |
|
| 2025 |
+# EO stack |
|
| 2026 |
+ |
|
| 1886 | 2027 |
# BO swarm |
| 1887 | 2028 |
|
| 1888 | 2029 |
__docker_swarm_commands() {
|
| ... | ... |
@@ -2451,6 +2592,23 @@ __docker_subcommand() {
|
| 2451 | 2451 |
;; |
| 2452 | 2452 |
esac |
| 2453 | 2453 |
;; |
| 2454 |
+ (stack) |
|
| 2455 |
+ local curcontext="$curcontext" state |
|
| 2456 |
+ _arguments $(__docker_arguments) \ |
|
| 2457 |
+ $opts_help \ |
|
| 2458 |
+ "($help -): :->command" \ |
|
| 2459 |
+ "($help -)*:: :->option-or-argument" && ret=0 |
|
| 2460 |
+ |
|
| 2461 |
+ case $state in |
|
| 2462 |
+ (command) |
|
| 2463 |
+ __docker_stack_commands && ret=0 |
|
| 2464 |
+ ;; |
|
| 2465 |
+ (option-or-argument) |
|
| 2466 |
+ curcontext=${curcontext%:*:*}:docker-${words[-1]}:
|
|
| 2467 |
+ __docker_stack_subcommand && ret=0 |
|
| 2468 |
+ ;; |
|
| 2469 |
+ esac |
|
| 2470 |
+ ;; |
|
| 2454 | 2471 |
(swarm) |
| 2455 | 2472 |
local curcontext="$curcontext" state |
| 2456 | 2473 |
_arguments $(__docker_arguments) \ |