forked from monzo/orchestra
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bash autocompletion with new script + add
.
alias
- Bash completion was rewritten from scratch as `.Before` is no longer called by github.com/urface/cli since v1.22.10 (see urfave/cli#1094). There might be a better way to do so, but with the additions of stacks finding all "service.***" in the current porject path seemed like a good start. - Add a `.` alias in arg parsing allowing a stack or a service to be acted upon when the user is currently in its directory.
- Loading branch information
Showing
11 changed files
with
103 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,65 @@ | ||
#! /bin/bash | ||
#!/bin/bash | ||
|
||
_cli_bash_autocomplete() { | ||
local cur prev opts base | ||
_orchestra_find_projectdir() { | ||
filename="orchestra.yml" | ||
current_dir=$(pwd) | ||
while [ "$current_dir" != "/" ]; do | ||
if [ -f "$current_dir/$filename" ]; then | ||
echo "${current_dir}" | ||
break | ||
fi | ||
current_dir=$(dirname "$current_dir") | ||
done | ||
} | ||
|
||
_orchestra_targets_autcomplete() { | ||
projdir=$(_orchestra_find_projectdir) | ||
svcs=$(cd "${projdir}" 2>/dev/null && ls -d -- **/service.* 2>/dev/null) | ||
stacks=$(echo "${svcs}" | cut -d/ -f-1 | sort -u) | ||
echo "${stacks} ${svcs}" | ||
} | ||
|
||
_orchestra_bash_autocomplete() { | ||
local cur prev opts | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
opts="build export install logs ps restart start stop test help" | ||
targets=$(_orchestra_targets_autcomplete) | ||
case "${COMP_WORDS[1]}" in | ||
build|install|logs|ps|stop) | ||
COMPREPLY=( $(compgen -W "${targets}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
test) | ||
if [[ "${prev}" == "test" || "${prev}" =~ --* ]]; then | ||
COMPREPLY=( $(compgen -W "--verbose --race" -- ${cur}) ) | ||
fi | ||
COMPREPLY+=( $(compgen -W "${targets}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
start|restart) | ||
if [[ "${prev}" == "start" || "${prev}" == "restart" ]]; then | ||
COMPREPLY=( $(compgen -W "--logs --attach" -- ${cur}) ) | ||
fi | ||
COMPREPLY+=( $(compgen -W "${targets}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
*) | ||
if [[ "${prev}" == "orchestra" ]]; then | ||
COMPREPLY=( $(compgen -W "--help --version --config" -- ${cur}) ) | ||
fi | ||
if [[ "${prev}" == "--help" || "${prev}" == "--version" ]]; then | ||
return 0 | ||
fi | ||
if [[ "${prev}" == "--config" ]]; then | ||
COMPREPLY=( $(compgen -f -- ${cur}) ) | ||
return 0 | ||
fi | ||
COMPREPLY+=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
esac | ||
} | ||
|
||
complete -F _cli_bash_autocomplete orchestra | ||
complete -F _orchestra_bash_autocomplete orchestra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters