From 8c5fc6fc265c5d8557f17a18b778c398a2c6f27b Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Wed, 31 Aug 2022 02:24:45 +0300 Subject: [PATCH] completion: delete the completion scripts of `@completely/cli` (#87) --- scripts/completions/README.md | 13 - scripts/completions/_caddy | 166 ---- scripts/completions/bash-completion | 1210 --------------------------- scripts/completions/caddy.json | 367 -------- scripts/completions/generate.sh | 4 - 5 files changed, 1760 deletions(-) delete mode 100644 scripts/completions/README.md delete mode 100644 scripts/completions/_caddy delete mode 100644 scripts/completions/bash-completion delete mode 100644 scripts/completions/caddy.json delete mode 100755 scripts/completions/generate.sh diff --git a/scripts/completions/README.md b/scripts/completions/README.md deleted file mode 100644 index 527f248..0000000 --- a/scripts/completions/README.md +++ /dev/null @@ -1,13 +0,0 @@ -The shell completion scripts are generated using the tool [@completely/cli](https://github.com/fvictorio/completely). The `caddy.json` file contains the spec of the caddy command. The shell completion scripts are generated based on the spec as defined in the JSON file. - -## How - -- Install `completely` - - yarn: `yarn global add @completely/cli` - - npm: `npm i -g @completely/cli` - -- Run `./generate.sh` - -- Place the generated files in the designated directories: - - bash: `sudo cp bash-completion /etc/bash_completion.d/caddy` - - zsh: `fpath=(/path/to/completion/script/dir $fpath)` diff --git a/scripts/completions/_caddy b/scripts/completions/_caddy deleted file mode 100644 index 66f50b7..0000000 --- a/scripts/completions/_caddy +++ /dev/null @@ -1,166 +0,0 @@ -#compdef caddy - -function _caddy { - local _line - - _arguments -C \ - "1: :(adapt build-info environ file-server fmt hash-password help list-modules reload reverse-proxy run start stop trust untrust validate version)" \ - "*::arg:->args" - - case $line[1] in - adapt) - __caddy_adapt - ;; - build-info) - __caddy_build-info - ;; - environ) - __caddy_environ - ;; - file-server) - __caddy_file-server - ;; - fmt) - __caddy_fmt - ;; - hash-password) - __caddy_hash-password - ;; - help) - __caddy_help - ;; - list-modules) - __caddy_list-modules - ;; - reload) - __caddy_reload - ;; - reverse-proxy) - __caddy_reverse-proxy - ;; - run) - __caddy_run - ;; - start) - __caddy_start - ;; - stop) - __caddy_stop - ;; - trust) - __caddy_trust - ;; - untrust) - __caddy_untrust - ;; - validate) - __caddy_validate - ;; - version) - __caddy_version - ;; - esac -} - -function __caddy_adapt { - _arguments \ - "--pretty: :" \ - "--validate: :" \ - "--adapter: :_files" \ - "--config: :_files" \ - -} -function __caddy_build-info { - -} -function __caddy_environ { - -} -function __caddy_file-server { - _arguments \ - "--browse: :" \ - "--templates: :" \ - "--domain: :_files" \ - "--listen: :_files" \ - "--root: :_dirs" \ - -} -function __caddy_fmt { - _arguments \ - "--overwrite: :" \ - -} -function __caddy_hash-password { - _arguments \ - "--algorithm: :_files" \ - "--plaintext: :_files" \ - "--salt: :_files" \ - -} -function __caddy_help { - -} -function __caddy_list-modules { - _arguments \ - "--versions: :" \ - -} -function __caddy_reload { - _arguments \ - "--adapter: :_files" \ - "--config: :_files" \ - "--address: :_files" \ - -} -function __caddy_reverse-proxy { - _arguments \ - "--change-host-header: :" \ - "--from: :_files" \ - "--to: :_files" \ - -} -function __caddy_run { - _arguments \ - "--environ: :" \ - "--resume: :" \ - "--watch: :" \ - "--adapter: :_files" \ - "--config: :_files" \ - "--pingback: :_files" \ - "--pidfile: :_files" \ - -} -function __caddy_start { - _arguments \ - "--watch: :" \ - "--adapter: :_files" \ - "--config: :_files" \ - "--pidfile: :_files" \ - -} -function __caddy_stop { - _arguments \ - "--address: :_files" \ - -} -function __caddy_trust { - -} -function __caddy_untrust { - _arguments \ - "--ca: :_files" \ - "--cert: :_files" \ - -} -function __caddy_validate { - _arguments \ - "--config: :_files" \ - "--adapter: :_files" \ - -} -function __caddy_version { - -} - -_caddy - diff --git a/scripts/completions/bash-completion b/scripts/completions/bash-completion deleted file mode 100644 index 1da7f36..0000000 --- a/scripts/completions/bash-completion +++ /dev/null @@ -1,1210 +0,0 @@ -#!/usr/bin/env bash - -# helper method -declare -f _contains_element > /dev/null || _contains_element() { - local e match="$1" - shift - for e; do [[ "$e" == "$match" ]] && return 0; done - return 1 -} - -_caddy_completions() -{ - # get current word, words array, current word index, and previous word, ignoring ":" as a wordbreak - local cur cword words - _get_comp_words_by_ref -n ":" cur words cword prev - - # complete subcommands list - if [ "$cword" -eq "1" ] && [ "adapt build-info environ file-server fmt hash-password help list-modules reload reverse-proxy run start stop trust untrust validate version" != "" ]; then - COMPREPLY=($(compgen -W "adapt build-info environ file-server fmt hash-password help list-modules reload reverse-proxy run start stop trust untrust validate version" -- "$cur")) - __ltrim_colon_completions "$cur" - return - fi - - local subcommand="${words[1]}" - - local args used_flags used_args index - - # register completions for each subcommand - if [ "${subcommand}" == "adapt" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--pretty" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - if [ "${args[0]}" == "--validate" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--adapter" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--config" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--adapter" ]]; then - COMPREPLY=() - if command -v grep > /dev/null && command -v sed > /dev/null && command -v tr > /dev/null; then - COMPREPLY=($(compgen -W "$(caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr ' -' ' ')" -- "$cur")) - fi - return - fi - if [[ "$prev" == "--config" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--pretty" "${used_flags[@]}"; then - completion+=("--pretty") - fi - if ! _contains_element "--validate" "${used_flags[@]}"; then - completion+=("--validate") - fi - if ! _contains_element "--adapter" "${used_flags[@]}"; then - completion+=("--adapter") - fi - if ! _contains_element "--config" "${used_flags[@]}"; then - completion+=("--config") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "build-info" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "environ" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "file-server" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--browse" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - if [ "${args[0]}" == "--templates" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--domain" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--listen" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--root" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--domain" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--listen" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--root" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -d -- "$cur")) - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--browse" "${used_flags[@]}"; then - completion+=("--browse") - fi - if ! _contains_element "--templates" "${used_flags[@]}"; then - completion+=("--templates") - fi - if ! _contains_element "--domain" "${used_flags[@]}"; then - completion+=("--domain") - fi - if ! _contains_element "--listen" "${used_flags[@]}"; then - completion+=("--listen") - fi - if ! _contains_element "--root" "${used_flags[@]}"; then - completion+=("--root") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "fmt" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--overwrite" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--overwrite" "${used_flags[@]}"; then - completion+=("--overwrite") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - if [[ "${#used_args[@]}" -eq "0" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - - return - fi - if [ "${subcommand}" == "hash-password" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [ "${args[0]}" == "--algorithm" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--plaintext" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--salt" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--algorithm" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--plaintext" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--salt" ]]; then - COMPREPLY=() - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--algorithm" "${used_flags[@]}"; then - completion+=("--algorithm") - fi - if ! _contains_element "--plaintext" "${used_flags[@]}"; then - completion+=("--plaintext") - fi - if ! _contains_element "--salt" "${used_flags[@]}"; then - completion+=("--salt") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "help" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - if [[ "${#used_args[@]}" -eq "0" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -W "adapt build-info environ file-server fmt hash-password help list-modules reload reverse-proxy run stop trust untrust validate" -- "$cur")) - return - fi - - return - fi - if [ "${subcommand}" == "list-modules" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--versions" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--versions" "${used_flags[@]}"; then - completion+=("--versions") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "reload" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [ "${args[0]}" == "--adapter" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--config" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--address" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--adapter" ]]; then - COMPREPLY=() - if command -v grep > /dev/null && command -v sed > /dev/null && command -v tr > /dev/null; then - COMPREPLY=($(compgen -W "$(caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr ' -' ' ')" -- "$cur")) - fi - return - fi - if [[ "$prev" == "--config" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - if [[ "$prev" == "--address" ]]; then - COMPREPLY=() - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--adapter" "${used_flags[@]}"; then - completion+=("--adapter") - fi - if ! _contains_element "--config" "${used_flags[@]}"; then - completion+=("--config") - fi - if ! _contains_element "--address" "${used_flags[@]}"; then - completion+=("--address") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "reverse-proxy" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--change-host-header" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--from" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--to" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--from" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--to" ]]; then - COMPREPLY=() - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--change-host-header" "${used_flags[@]}"; then - completion+=("--change-host-header") - fi - if ! _contains_element "--from" "${used_flags[@]}"; then - completion+=("--from") - fi - if ! _contains_element "--to" "${used_flags[@]}"; then - completion+=("--to") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "run" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--environ" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - if [ "${args[0]}" == "--resume" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - if [ "${args[0]}" == "--watch" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--adapter" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--config" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--pingback" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--pidfile" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--adapter" ]]; then - COMPREPLY=() - if command -v grep > /dev/null && command -v sed > /dev/null && command -v tr > /dev/null; then - COMPREPLY=($(compgen -W "$(caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr ' -' ' ')" -- "$cur")) - fi - return - fi - if [[ "$prev" == "--config" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - if [[ "$prev" == "--pingback" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--pidfile" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--environ" "${used_flags[@]}"; then - completion+=("--environ") - fi - if ! _contains_element "--resume" "${used_flags[@]}"; then - completion+=("--resume") - fi - if ! _contains_element "--watch" "${used_flags[@]}"; then - completion+=("--watch") - fi - if ! _contains_element "--adapter" "${used_flags[@]}"; then - completion+=("--adapter") - fi - if ! _contains_element "--config" "${used_flags[@]}"; then - completion+=("--config") - fi - if ! _contains_element "--pingback" "${used_flags[@]}"; then - completion+=("--pingback") - fi - if ! _contains_element "--pidfile" "${used_flags[@]}"; then - completion+=("--pidfile") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "start" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--watch" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - if [ "${args[0]}" == "--adapter" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--config" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--pidfile" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--adapter" ]]; then - COMPREPLY=() - if command -v grep > /dev/null && command -v sed > /dev/null && command -v tr > /dev/null; then - COMPREPLY=($(compgen -W "$(caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr ' -' ' ')" -- "$cur")) - fi - return - fi - if [[ "$prev" == "--config" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - if [[ "$prev" == "--pidfile" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--watch" "${used_flags[@]}"; then - completion+=("--watch") - fi - if ! _contains_element "--adapter" "${used_flags[@]}"; then - completion+=("--adapter") - fi - if ! _contains_element "--config" "${used_flags[@]}"; then - completion+=("--config") - fi - if ! _contains_element "--pidfile" "${used_flags[@]}"; then - completion+=("--pidfile") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "stop" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [ "${args[0]}" == "--address" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--address" ]]; then - COMPREPLY=() - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--address" "${used_flags[@]}"; then - completion+=("--address") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "trust" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "untrust" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [ "${args[0]}" == "--ca" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--cert" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--ca" ]]; then - COMPREPLY=() - return - fi - if [[ "$prev" == "--cert" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--ca" "${used_flags[@]}"; then - completion+=("--ca") - fi - if ! _contains_element "--cert" "${used_flags[@]}"; then - completion+=("--cert") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "validate" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - if [ "${args[0]}" == "--config" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - if [ "${args[0]}" == "--adapter" ]; then - used_flags+=("${args[0]}") - args=("${args[@]:2}") - index=$((index+2)) - continue - fi - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - if [[ "$prev" == "--config" ]]; then - COMPREPLY=() - COMPREPLY=($(compgen -f -- "$cur")) - return - fi - if [[ "$prev" == "--adapter" ]]; then - COMPREPLY=() - if command -v grep > /dev/null && command -v sed > /dev/null && command -v tr > /dev/null; then - COMPREPLY=($(compgen -W "$(caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr ' -' ' ')" -- "$cur")) - fi - return - fi - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - if ! _contains_element "--config" "${used_flags[@]}"; then - completion+=("--config") - fi - if ! _contains_element "--adapter" "${used_flags[@]}"; then - completion+=("--adapter") - fi - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi - if [ "${subcommand}" == "version" ]; then - local args_shift=2 - # get the list of already used flags and args, ignoring the current word - args=("${words[@]:args_shift}") # args without command and subcommand - used_flags=() - used_args=() - index=0 - - while [ "${#args[@]}" -gt 0 ]; do - if [ "${index}" -eq "$((cword-args_shift))" ]; then - # ignore current word - args=("${args[@]:1}") - index=$((index+1)) - continue - fi - - - - if [[ "${args[0]}" != "-"* ]]; then - used_args+=("${args[0]}") - fi - args=("${args[@]:1}") - index=$((index+1)) - done - - - if [[ $cur == -* ]]; then - # flags - completion=() - - if [[ $cur != --* ]]; then - true - fi - - - COMPREPLY=($(compgen -W "${completion[*]}" -- "$cur")) - return - fi - - - return - fi -} - -# register completion -complete -F _caddy_completions caddy - diff --git a/scripts/completions/caddy.json b/scripts/completions/caddy.json deleted file mode 100644 index 10d174f..0000000 --- a/scripts/completions/caddy.json +++ /dev/null @@ -1,367 +0,0 @@ -{ - "command": "caddy", - "subcommands": [ - { - "command": "adapt", - "args": [], - "flags": [ - { - "name": "adapter", - "type": "string", - "completion": { - "type": "command", - "command": "caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr '\n' ' '", - "requiredCommands": ["grep", "sed", "tr"] - } - }, - { - "name": "config", - "type": "string", - "required": true, - "completion": { - "type": "files" - } - }, - { - "name": "pretty", - "type": "boolean" - }, - { - "name": "validate", - "type": "boolean" - } - ] - }, - { - "command": "build-info", - "args": [], - "flags": [] - }, - { - "command": "environ", - "args": [], - "flags": [] - }, - { - "command": "file-server", - "args": [], - "flags": [ - { - "name": "browse", - "type": "boolean" - }, - { - "name": "domain", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "listen", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "root", - "type": "string", - "completion": { - "type": "directories" - } - }, - { - "name": "templates", - "type": "boolean" - } - ] - }, - { - "command": "fmt", - "flags": [ - { - "name": "overwrite", - "type": "boolean" - } - ], - "args": [ - { - "name": "path", - "completion": { - "type": "files" - } - } - ] - }, - { - "command": "hash-password", - "args": [], - "flags": [ - { - "name": "algorithm", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "plaintext", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "salt", - "type": "string", - "completion": { - "type": "string" - } - } - ] - }, - { - "command": "help", - "flags": [], - "args": [ - { - "name": "subcommands", - "completion": { - "type": "oneOf", - "values": [ - "adapt", - "build-info", - "environ", - "file-server", - "fmt", - "hash-password", - "help", - "list-modules", - "reload", - "reverse-proxy", - "run", - "stop", - "trust", - "untrust", - "validate" - ] - } - } - ] - }, - { - "command": "list-modules", - "args": [], - "flags": [ - { - "name": "versions", - "type": "boolean" - } - ] - }, - { - "command": "reload", - "args": [], - "flags": [ - { - "name": "adapter", - "type": "string", - "completion": { - "type": "command", - "command": "caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr '\n' ' '", - "requiredCommands": ["grep", "sed", "tr"] - } - }, - { - "name": "config", - "type": "string", - "required": true, - "completion": { - "type": "files" - } - }, - { - "name": "address", - "type": "string", - "completion": { - "type": "string" - } - } - ] - }, - { - "command": "reverse-proxy", - "args": [], - "flags": [ - { - "name": "change-host-header", - "type": "boolean" - }, - { - "name": "from", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "to", - "type": "string", - "completion": { - "type": "string" - } - } - ] - }, - { - "command": "run", - "args": [], - "flags": [ - { - "name": "adapter", - "type": "string", - "completion": { - "type": "command", - "command": "caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr '\n' ' '", - "requiredCommands": ["grep", "sed", "tr"] - } - }, - { - "name": "config", - "type": "string", - "required": true, - "completion": { - "type": "files" - } - }, - { - "name": "environ", - "type": "boolean" - }, - { - "name": "pingback", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "resume", - "type": "boolean" - }, - { - "name": "watch", - "type": "boolean" - }, - { - "name": "pidfile", - "type": "string", - "completion": { - "type": "files" - } - } - ] - }, - { - "command": "start", - "args": [], - "flags": [ - { - "name": "adapter", - "type": "string", - "completion": { - "type": "command", - "command": "caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr '\n' ' '", - "requiredCommands": ["grep", "sed", "tr"] - } - }, - { - "name": "config", - "type": "string", - "required": true, - "completion": { - "type": "files" - } - }, - { - "name": "watch", - "type": "boolean" - }, - { - "name": "pidfile", - "type": "string", - "completion": { - "type": "files" - } - } - ] - }, - { - "command": "stop", - "args": [], - "flags": [ - { - "name": "address", - "type": "string", - "completion": { - "type": "string" - } - } - ] - }, - { - "command": "trust", - "args": [], - "flags": [] - }, - { - "command": "untrust", - "args": [], - "flags": [ - { - "name": "ca", - "type": "string", - "completion": { - "type": "string" - } - }, - { - "name": "cert", - "type": "string", - "completion": { - "type": "files" - } - } - ] - }, - { - "command": "validate", - "args": [], - "flags": [ - { - "name": "config", - "type": "string", - "required": true, - "completion": { - "type": "files" - } - }, - { - "name": "adapter", - "type": "string", - "completion": { - "type": "command", - "command": "caddy list-modules | grep adapters | sed s/caddy.adapters.// | tr '\n' ' '", - "requiredCommands": ["grep", "sed", "tr"] - } - } - ] - }, - { - "command": "version", - "args": [], - "flags": [] - } - ] -} diff --git a/scripts/completions/generate.sh b/scripts/completions/generate.sh deleted file mode 100755 index 7e2008e..0000000 --- a/scripts/completions/generate.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -completely --shell zsh caddy.json > _caddy -completely --shell bash caddy.json > bash-completion