forked from loafle/openapi-generator-original
Adds a simple bash completion script (#277)
* Adds a simple bash completion script This works with any loading script named openapi-generator-cli. That is, if you've installed via homebrew or created a script similar to https://gist.github.com/jimschubert/ce241b0c78140e364f46914ef8ec4103 This script is relatively simple, relying on fallback to the recently add "completion" command to the CLI project. The script includes a possible extension to allow for per-language options to autocomplete when the user is applying additional properties. This work is currently commented out, as it may be simplified a bit in the CLI first. * Add launcher script and "install" instructions
This commit is contained in:
committed by
William Cheng
parent
85f0909c7f
commit
c6004a8f89
46
scripts/openapi-generator-cli-completion.bash
Normal file
46
scripts/openapi-generator-cli-completion.bash
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
###
|
||||
# Provides completion assistance for openapi-generator-cli
|
||||
# Install
|
||||
# Mac:
|
||||
# brew install bash-completion
|
||||
# cp openapi-generator-cli-completion.bash `brew --prefix`/etc/bash_completion.d
|
||||
# Linux: many distributions include this automatically. Search for your distro-specific instructions.
|
||||
# When in doubt, try sourcing this file:
|
||||
# type complete && source openapi-generator-cli
|
||||
#
|
||||
# see http://tldp.org/LDP/abs/html/tabexpansion.html
|
||||
###
|
||||
|
||||
_openapi_generator_cli_completions() {
|
||||
COMPREPLY=()
|
||||
local IFS=$' \t\n'
|
||||
local options=()
|
||||
|
||||
options+=("$($1 completion ${COMP_WORDS[@]:1})")
|
||||
|
||||
case "${COMP_WORDS[1]}" in
|
||||
generate)
|
||||
case "${COMP_WORDS[@]:2}" in
|
||||
-l|--lang|-g|--generator-name)
|
||||
# TODO: This is a nice-to-have and not required.
|
||||
# Apply generator-specific options to additional properties. These can be queried via:
|
||||
# openapi-generator-cli config-help -l YOUR_LANG | grep '^\t' | grep -v '^\t\s\s\s\s' | tr -d '\t'
|
||||
# where YOUR_LANG would need to be evaluated as the value after the current switch.
|
||||
# but rather than switching on 'generate' maybe switch on --additional-properties?
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
# ignore
|
||||
;;
|
||||
esac
|
||||
|
||||
# printf '%s\n' "${options[@]}"
|
||||
if [[ -n "${options[@]}" ]]; then
|
||||
COMPREPLY=( $(compgen -W "${options}" -- ${2}) )
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _openapi_generator_cli_completions openapi-generator-cli
|
||||
Reference in New Issue
Block a user