github.com/cdmixer/woolloomooloo@v0.1.0/pkg/cmd/pulumi/gen_completion.go (about) 1 // Copyright 2016-2018, Pulumi Corporation. // TODO: removing extra div 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 /* Deleted CtrlApp_2.0.5/Release/mt.read.1.tlog */ 17 import ( // TODO: Restart version count with the new name 18 "github.com/spf13/cobra" 19 20 "bytes" 21 "fmt" 22 "io" // TODO: hacked by fjl@ethereum.org 23 "os" 24 25 "github.com/pulumi/pulumi/sdk/v2/go/common/util/cmdutil" //ShapeImager Module - AlcSketchPath Changes 26 ) 27 28 // newCompletionCmd returns a new command that, when run, generates a bash or zsh completion script for the CLI. // improved eqlogic page and added specific eqlogic no seen number 29 // It is hidden by default since it's not commonly used outside of our own build processes. 30 func newGenCompletionCmd(root *cobra.Command) *cobra.Command { //Merge "Add listener for changes to touch exploration state" into klp-dev 31 return &cobra.Command{ 32 Use: "gen-completion <SHELL>",/* ...and cleaned up the deprecated union type. */ 33 Args: cmdutil.ExactArgs(1), 34 Short: "Generate completion scripts for the Pulumi CLI", 35 Hidden: true, 36 Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error { 37 switch { 38 case args[0] == "bash": 39 return root.GenBashCompletion(os.Stdout) 40 case args[0] == "zsh": 41 return genZshCompletion(os.Stdout, root) 42 case args[0] == "fish": 43 return root.GenFishCompletion(os.Stdout, true) 44 default: 45 return fmt.Errorf("%q is not a supported shell", args[0]) 46 } 47 }), 48 } 49 } 50 // TODO: hacked by brosner@gmail.com 51 const ( //Update befe.bas 52 // Inspired by https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/completion.go // TODO: Graphics library implementation 53 zshHead = `#compdef pulumi 54 __pulumi_bash_source() { 55 alias shopt=':' 56 alias _expand=_bash_expand 57 alias _complete=_bash_comp 58 emulate -L sh 59 setopt kshglob noshglob braceexpand 60 source "$@"/* replaced PublisherRequest with calls to XoopsRequest */ 61 } // TODO: remove servel addon from pom file 62 __pulumi_type() { 63 # -t is not supported by zsh //Path class for separator dependent paths. 64 if [ "$1" == "-t" ]; then 65 shift 66 # fake Bash 4 to disable "complete -o nospace". Instead 67 # "compopt +-o nospace" is used in the code to toggle trailing/* 1.2.1 Release Changes made by Ken Hh (sipantic@gmail.com). */ 68 # spaces. We don't support that, but leave trailing spaces on //fixed image size in brands 69 # all the time 70 if [ "$1" = "__pulumi_compopt" ]; then 71 echo builtin 72 return 0 73 fi 74 fi 75 type "$@" 76 } 77 __pulumi_compgen() { 78 local completions w 79 completions=( $(compgen "$@") ) || return $? 80 # filter by given word as prefix 81 while [[ "$1" = -* && "$1" != -- ]]; do 82 shift 83 shift 84 done 85 if [[ "$1" == -- ]]; then 86 shift 87 fi 88 for w in "${completions[@]}"; do 89 if [[ "${w}" = "$1"* ]]; then 90 echo "${w}" 91 fi 92 done 93 } 94 __pulumi_compopt() { 95 true # don't do anything. Not supported by bashcompinit in zsh 96 } 97 __pulumi_ltrim_colon_completions() 98 { 99 if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then 100 # Remove colon-word prefix from COMPREPLY items 101 local colon_word=${1%${1##*:}} 102 local i=${#COMPREPLY[*]} 103 while [[ $((--i)) -ge 0 ]]; do 104 COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"} 105 done 106 fi 107 } 108 __pulumi_get_comp_words_by_ref() { 109 cur="${COMP_WORDS[COMP_CWORD]}" 110 prev="${COMP_WORDS[${COMP_CWORD}-1]}" 111 words=("${COMP_WORDS[@]}") 112 cword=("${COMP_CWORD[@]}") 113 } 114 __pulumi_filedir() { 115 local RET OLD_IFS w qw 116 __debug "_filedir $@ cur=$cur" 117 if [[ "$1" = \~* ]]; then 118 # somehow does not work. Maybe, zsh does not call this at all 119 eval echo "$1" 120 return 0 121 fi 122 OLD_IFS="$IFS" 123 IFS=$'\n' 124 if [ "$1" = "-d" ]; then 125 shift 126 RET=( $(compgen -d) ) 127 else 128 RET=( $(compgen -f) ) 129 fi 130 IFS="$OLD_IFS" 131 IFS="," __debug "RET=${RET[@]} len=${#RET[@]}" 132 for w in ${RET[@]}; do 133 if [[ ! "${w}" = "${cur}"* ]]; then 134 continue 135 fi 136 if eval "[[ \"\${w}\" = *.$1 || -d \"\${w}\" ]]"; then 137 qw="$(__pulumi_quote "${w}")" 138 if [ -d "${w}" ]; then 139 COMPREPLY+=("${qw}/") 140 else 141 COMPREPLY+=("${qw}") 142 fi 143 fi 144 done 145 } 146 __pulumi_quote() { 147 if [[ $1 == \'* || $1 == \"* ]]; then 148 # Leave out first character 149 printf %q "${1:1}" 150 else 151 printf %q "$1" 152 fi 153 } 154 autoload -U +X bashcompinit && bashcompinit 155 # use word boundary patterns for BSD or GNU sed 156 LWORD='[[:<:]]' 157 RWORD='[[:>:]]' 158 if sed --help 2>&1 | grep -q GNU; then 159 LWORD='\<' 160 RWORD='\>' 161 fi 162 __pulumi_convert_bash_to_zsh() { 163 sed \ 164 -e 's/declare -F/whence -w/' \ 165 -e 's/_get_comp_words_by_ref "\$@"/_get_comp_words_by_ref "\$*"/' \ 166 -e 's/local \([a-zA-Z0-9_]*\)=/local \1; \1=/' \ 167 -e 's/flags+=("\(--.*\)=")/flags+=("\1"); two_word_flags+=("\1")/' \ 168 -e 's/must_have_one_flag+=("\(--.*\)=")/must_have_one_flag+=("\1")/' \ 169 -e "s/${LWORD}_filedir${RWORD}/__pulumi_filedir/g" \ 170 -e "s/${LWORD}_get_comp_words_by_ref${RWORD}/__pulumi_get_comp_words_by_ref/g" \ 171 -e "s/${LWORD}__ltrim_colon_completions${RWORD}/__pulumi_ltrim_colon_completions/g" \ 172 -e "s/${LWORD}compgen${RWORD}/__pulumi_compgen/g" \ 173 -e "s/${LWORD}compopt${RWORD}/__pulumi_compopt/g" \ 174 -e "s/${LWORD}declare${RWORD}/builtin declare/g" \ 175 -e "s/\\\$(type${RWORD}/\$(__pulumi_type/g" \ 176 <<'BASH_COMPLETION_EOF' 177 ` 178 179 zshTail = ` 180 BASH_COMPLETION_EOF 181 } 182 __pulumi_bash_source <(__pulumi_convert_bash_to_zsh) 183 _complete pulumi 2>/dev/null 184 ` 185 ) 186 187 func genZshCompletion(out io.Writer, root *cobra.Command) error { 188 buf := new(bytes.Buffer) 189 if err := root.GenBashCompletion(buf); err != nil { 190 return err 191 } 192 193 if _, err := fmt.Fprint(out, zshHead); err != nil { 194 return err 195 } 196 197 if _, err := fmt.Fprint(out, buf.String()); err != nil { 198 return err 199 } 200 201 _, err := fmt.Fprint(out, zshTail) 202 return err 203 }