autocompletion 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. #
  3. # Bash completion for OpenConnect
  4. #
  5. # Copyright © David Woodhouse <dwmw2@infradead.org>
  6. #
  7. # Author: David Woodhouse <dwmw2@infradead.org>
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public License
  11. # version 2.1, as published by the Free Software Foundation.
  12. #
  13. # This program is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # Lesser General Public License for more details.
  17. # Consider a command line like the following:
  18. #
  19. # openconnect -c --authenticate\ -k -k "'"'"'.pem --authgroup 'foo
  20. # bar' --o\s linux-64 myserver
  21. OPENCONNECT="${OPENCONNECT:-${top_builddir}/openconnect}"
  22. if ! [ -x $OPENCONNECT ]; then
  23. echo "$OPENCONNECT is not executable. Are you cross-compiling for Windows?"
  24. exit 77
  25. fi
  26. do_test()
  27. {
  28. if [ "$(COMP_CWORD=$WORD $OPENCONNECT --autocomplete "$@")" != "$RESULT" ]; then
  29. echo "Autocomplete failed (word $WORD) for '$@'"
  30. exit 1
  31. fi
  32. echo "Autocomplete OK (word $WORD) for '$@'"
  33. }
  34. WORD=1
  35. RESULT="HOSTNAME"
  36. do_test ""
  37. WORD=1
  38. RESULT="--certificate"
  39. do_test -c
  40. WORD=3
  41. RESULT="FILENAME
  42. !*.@(pem|der|p12|crt)"
  43. do_test foo -k ''
  44. WORD=2
  45. RESULT="--protocol"
  46. do_test somehost --proto
  47. WORD=1
  48. RESULT="HOSTNAME"
  49. do_test somehost --proto
  50. WORD=3
  51. RESULT="FILENAME
  52. !*.@(pem|der|crt)"
  53. do_test foo --cafile ''
  54. WORD=4
  55. RESULT="none
  56. off
  57. all
  58. stateless"
  59. do_test -k foo --compr ''
  60. WORD=1
  61. RESULT="EXECUTABLE
  62. ''
  63. -s"
  64. do_test -s/bin