adds bash completion for argument options for oidc-gen
@@ -25,12 +25,30 @@ _needArgument() {
return 0
}
-#TODO completion for options
+_matchFiles() {
+ local IFS=$'\n'
+ local LASTCHAR=' '
+
+ COMPREPLY=($(compgen -o plusdirs -f -- "$1"))
+
+ if [ ${#COMPREPLY[@]} = 1 ]; then
+ [ -d "$COMPREPLY" ] && LASTCHAR=/
+ COMPREPLY=$(printf %q%s "$COMPREPLY" "$LASTCHAR")
+ else
+ for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
+ [ -d "${COMPREPLY[$i]}" ] && COMPREPLY[$i]=${COMPREPLY[$i]}/
+ done
+ fi
+
+ return 0
+}
+
_oidc-gen() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
+ prevprev="${COMP_WORDS[COMP_CWORD-2]}"
local IFS=$'\t\n'
opts="--clients
--accounts
@@ -61,6 +79,36 @@ _oidc-gen() {
fi
shortnames=`ls $agentdir | grep -v "config" | sed -e 's/$/& /g'`
+ if [[ "$cur" == "=" ]]; then
+ prev+="="
+ cur=""
+ fi
+ if [[ "$prev" == "=" ]]; then
+ prev="$prevprev$prev"
+ fi
+ case $prev in
+ "--print=")
+ _matchFiles ${cur}
+ local oidcDirFiles=`ls $agentdir | sed -e 's/$/& /g'`
+ COMPREPLY+=( $(compgen -W "${oidcDirFiles}" -- ${cur}) )
+ return 0
+ ;;
+ "--file=")
+ ;&
+ "--cp=")
+ ;&
+ "--output=")
+ _matchFiles ${cur}
+ return 0
+ ;;
+ "--flow=")
+ local IFS=$'#\n'
+ local someScopes="code #device #password #refresh "
+ COMPREPLY=( $(compgen -W "${someScopes}" -- ${cur}) )
+ return 0
+ ;;
+ esac
+
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
