completescript.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2019 Yunion
  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. package promputils
  15. const BASH_COMPLETE_SCRIPT_1 = `arr=()
  16. %s
  17. _climc()
  18. {
  19. local cur second
  20. local cmd
  21. local allopts subopts
  22. COMPREPLY=()
  23. cur="${COMP_WORDS[COMP_CWORD]}"
  24. for ((i = 0; i < ${#arr[@]}; i++))
  25. do
  26. line="${arr[$i]}"
  27. allopts[i]=${line%s`
  28. const BASH_COMPLETE_SCRIPT_2 = `%#*}
  29. subopts[i]=${line#*#}
  30. done
  31. # Add hints for help subcommand.
  32. allopts[i]="help"
  33. subopts[i]="${allopts[*]}"
  34. # Generate hints for subcommand.
  35. if [[ ${COMP_CWORD} -eq 1 ]]; then
  36. COMPREPLY=( $(compgen -W "${allopts[*]}" -- ${cur}) )
  37. return 0
  38. fi
  39. # Generate hints for options of subcommands.
  40. i=0
  41. second="${COMP_WORDS[1]}"
  42. for cmd in ${allopts[*]}
  43. do
  44. if [[ "$cmd" = "$second" ]]; then
  45. COMPREPLY=( $(compgen -W "${subopts[i]}" -- ${cur}) )
  46. break
  47. fi
  48. ((i++))
  49. done
  50. }
  51. complete -F _climc climc
  52. `
  53. const ZSH_COMPLETE_SCRIPT_1 = `arr=()
  54. %s
  55. _climc(){
  56. local curcontext="$curcontext" state line
  57. typeset -A opt_args
  58. count=1
  59. for ((i = 0; i < ${#arr[@]}; i++))
  60. do
  61. line="${arr[$i]}"
  62. allopts[count]=${line%s`