feat: update cli.sh

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-06-21 13:12:59 +08:00
parent dc46ab904a
commit 02fa9d8e30

57
cli.sh
View File

@ -1,10 +1,36 @@
#!/bin/bash #!/bin/bash
SHELL_PREFIX="[FAAS-CLI]"
# Shell Base Script
set -e set -e
c_red="\033[38;5;1m"
c_blue="\033[38;5;4m"
c_green="\033[38;5;2m"
c_reset="\033[0m"
c_yellow="\033[38;5;3m"
c_prefix="${c_blue}${SHELL_PREFIX}>>${c_reset}"
dateStr() {
echo -e "[$(date '+%H:%M:%S')]"
}
info() {
echo -e "${c_prefix}$(dateStr) ${*}"
}
warn() {
echo -e "${c_prefix}$(dateStr) ${c_yellow}${*}${c_reset}"
}
error() {
echo -e "${c_prefix}$(dateStr) ${c_red}${*}${c_reset}"
}
#====================
cd $(dirname $0)
# User Input Variable # User Input Variable
action=up action=
name=
type=micro
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
@ -12,14 +38,6 @@ while [[ $# -gt 0 ]]; do
action="$2" action="$2"
shift shift
;; ;;
-n|-p)
name="$2"
shift
;;
-t)
type="$2"
shift
;;
-*) -*)
echo "Illegal option $1" echo "Illegal option $1"
;; ;;
@ -28,12 +46,17 @@ while [[ $# -gt 0 ]]; do
done done
case "${action}" in case "${action}" in
up) undo)
faas-cli build -f ${name}.yml hash=$(git log -n 1 --format=format:%H)
faas-cli deploy -f ${name}.yml --label "com.openfaas.scale.zero=true" tag=$(git tag -l --contains=${hash})
;; if [[ -z "${tag}" ]]; then
create) error "last commit not have tag exit..."
faas-cli new ${name} --lang cc-server exit 0
fi
git reset HEAD^
git tag -d ${tag}
git push origin master -f
git push origin :${tag}
;; ;;
esac esac