Skip to content

Commit

Permalink
Update deployments completion to respect --state
Browse files Browse the repository at this point in the history
The possible deployments are taken from a database.
The database file is also passed on the command line.
If the user passes a database file, we'd like to list
the deployments from that file, and not the default one.
  • Loading branch information
Avaq committed Mar 29, 2020
1 parent 0ef91ba commit e1b9e63
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion _nix
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,19 @@ function _nix_completion () {
${main_options[*]} \
${nix_boilerplate_opts[*]} && return 0

local statecmd
if [[ "${opts[--state]}" || "${opts[-s]}" ]]; then
local statefile="${opt_args[--state]:-${opt_args[-s]}}"
if [[ "$statefile" == *.nixops && -f "$statefile" ]]; then
statecmd="--state $statefile"
fi
fi

case "$state" in
nixops_deployments)
local -a deployments=()
while read -r _ id _ name _; do deployments+=("$id" "$name")
done < <(nixops list | tail -n +4 | head -n -1)
done < <(nixops list $statecmd | tail -n +4 | head -n -1)
COMPREPLY=($(compgen -W "${deployments[*]}" -- "$cur"))
return
;;
Expand Down

0 comments on commit e1b9e63

Please sign in to comment.