From d3a63b09bd059c365df99ab401ecec72a38f9cd1 Mon Sep 17 00:00:00 2001 From: a-sansara Date: Sun, 30 Apr 2017 04:19:29 +0200 Subject: [PATCH] enhance display + add usage --- dist/bes-build | 53 +++++++++++++++++++++++++++++++++++++------------- src/build.sh | 11 ++++++----- src/display.sh | 15 +++++++++++--- src/main.sh | 11 ++++++----- src/usage.sh | 17 ++++++++++++++++ 5 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 src/usage.sh diff --git a/dist/bes-build b/dist/bes-build index ff27520..d2aab7a 100755 --- a/dist/bes-build +++ b/dist/bes-build @@ -9,7 +9,7 @@ bes.build(){ bes.echo.state $? fi if [ -f "$APP_BIN" ]; then - if [ "$1" = "-s" ]; then + if [ "$1" = "backup" ] || [ "$1" = "-b" ]; then bes.echo.action "backup last build to ${Coff}dist/$(date +%y%m%d)-$APP_NAME${Coff}" mv $APP_BIN $APP_DIR/dist/$(date +%y%m%d)-$APP_NAME else @@ -22,23 +22,24 @@ bes.build(){ bes.echo.action "reading ${Coff}src/" for entry in "$APP_DIR/src"/*.sh; do if [ "$(basename $entry)" != "main.sh" ]; then - bes.echo " - appending ${Coff}src/$(basename $entry)" + bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/$(basename $entry)" tail -n +2 "$entry" >> "$APP_BIN" fi done if [ -f "$APP_DIR/src/main.sh" ]; then tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" - bes.echo " - appending ${Coff}src/main.sh" + bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/main.sh" fi bes.echo.state 0 bes.echo.action "set execution mode" chmod +x $APP_BIN - bes.echo.state $? + done=$? + bes.echo.state $done + bes.echo.rs $done else bes.echo.error "no src/ directory. exit" bes.echo.state 1 fi - echo } BES_TERM_WIDTH=105 @@ -63,17 +64,17 @@ bes.echo(){ local isAction=${2:-'0'} local symbol=${3:-' *'} if [ ! "$BES_NOCOLOR" = 1 ]; then - local c=$Cok + local c=" " if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then c=$Caction fi if [ ! "$isAction" = 0 ]; then - c=" $Citem$symbol $c" + c=" $Citem$symbol $c" fi echo -e " $c$msg$Coff" else if [ ! "$isAction" = 0 ]; then - msg=" $symbol $msg" + msg=" $symbol $msg" fi echo -e "$msg" fi @@ -106,6 +107,15 @@ bes.echo.state(){ fi } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +bes.echo.rs(){ + local rs=${1:-0} + if [ "$rs" -eq 0 ]; then + echo -e "\n ${Cdone} done ${Coff}" + else + echo -e "\n ${Cfail} failed ${Coff}" + fi +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bes.echo.error(){ echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n" } @@ -168,24 +178,41 @@ bes.install(){ fi } +bes.usage(){ + echo -e " ${Cusa}Usage :${Coff}\n + ${Ccom}\tBuild current project (overwrite existing build) + ${Cspe}\tbes-build ${Copt} + ${Ccom}\tBuild current project and backup existing build + ${Cspe}\tbes-build ${Copt}-b${Ctext}, ${Copt}backup + ${Ccom}\tInstall or update bes-build on specified BINDIR directory or in /etc/local/bin directory + ${Cspe}\tbes-build ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ] + ${Ccom}\tDisplay program version + ${Cspe}\tbes-build ${Copt}-v${Ctext}, ${Copt}version + ${Ccom}\tDisplay this help + ${Cspe}\tbes-build ${Copt}-h${Ctext}, ${Copt}help" + + echo -e "${Coff}" +} + BES_BUILD_VERSION=0.3 APP_DIR=$(pwd) APP_NAME=$(basename $(pwd)) APP_BIN=$APP_DIR/dist/$APP_NAME bes.main(){ - if [ "$1" = "version" ]; then + if [ "$1" = "version" ] || [ "$1" = "-v" ]; then echo $BES_BUILD_VERSION else bes.title 'bes-build' $BES_BUILD_VERSION echo - if [ "$1" = "install" ]; then - bes.install $2 - elif [ -z "$1" ] || [ "$1" = "-s" ]; then + if [ "$1" = "install" ] || [ "$1" = "-i" ]; then + bes.install "$2" + elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then + bes.usage + elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then bes.build "$1" fi echo fi } - bes.main $* diff --git a/src/build.sh b/src/build.sh index f782516..5141f44 100644 --- a/src/build.sh +++ b/src/build.sh @@ -9,7 +9,7 @@ bes.build(){ bes.echo.state $? fi if [ -f "$APP_BIN" ]; then - if [ "$1" = "-s" ]; then + if [ "$1" = "backup" ] || [ "$1" = "-b" ]; then bes.echo.action "backup last build to ${Coff}dist/$(date +%y%m%d)-$APP_NAME${Coff}" mv $APP_BIN $APP_DIR/dist/$(date +%y%m%d)-$APP_NAME else @@ -22,21 +22,22 @@ bes.build(){ bes.echo.action "reading ${Coff}src/" for entry in "$APP_DIR/src"/*.sh; do if [ "$(basename $entry)" != "main.sh" ]; then - bes.echo " - appending ${Coff}src/$(basename $entry)" + bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/$(basename $entry)" tail -n +2 "$entry" >> "$APP_BIN" fi done if [ -f "$APP_DIR/src/main.sh" ]; then tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" - bes.echo " - appending ${Coff}src/main.sh" + bes.echo " ${Cspe}- ${Cok}appending ${Coff}src/main.sh" fi bes.echo.state 0 bes.echo.action "set execution mode" chmod +x $APP_BIN - bes.echo.state $? + done=$? + bes.echo.state $done + bes.echo.rs $done else bes.echo.error "no src/ directory. exit" bes.echo.state 1 fi - echo } diff --git a/src/display.sh b/src/display.sh index 0274fe7..2841d7c 100755 --- a/src/display.sh +++ b/src/display.sh @@ -22,17 +22,17 @@ bes.echo(){ local isAction=${2:-'0'} local symbol=${3:-' *'} if [ ! "$BES_NOCOLOR" = 1 ]; then - local c=$Cok + local c=" " if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then c=$Caction fi if [ ! "$isAction" = 0 ]; then - c=" $Citem$symbol $c" + c=" $Citem$symbol $c" fi echo -e " $c$msg$Coff" else if [ ! "$isAction" = 0 ]; then - msg=" $symbol $msg" + msg=" $symbol $msg" fi echo -e "$msg" fi @@ -65,6 +65,15 @@ bes.echo.state(){ fi } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +bes.echo.rs(){ + local rs=${1:-0} + if [ "$rs" -eq 0 ]; then + echo -e "\n ${Cdone} done ${Coff}" + else + echo -e "\n ${Cfail} failed ${Coff}" + fi +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bes.echo.error(){ echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n" } diff --git a/src/main.sh b/src/main.sh index d262387..539fd1c 100755 --- a/src/main.sh +++ b/src/main.sh @@ -6,18 +6,19 @@ BES_BUILD_VERSION=0.3 APP_BIN=$APP_DIR/dist/$APP_NAME bes.main(){ - if [ "$1" = "version" ]; then + if [ "$1" = "version" ] || [ "$1" = "-v" ]; then echo $BES_BUILD_VERSION else bes.title 'bes-build' $BES_BUILD_VERSION echo - if [ "$1" = "install" ]; then - bes.install $2 - elif [ -z "$1" ] || [ "$1" = "-s" ]; then + if [ "$1" = "install" ] || [ "$1" = "-i" ]; then + bes.install "$2" + elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then + bes.usage + elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then bes.build "$1" fi echo fi } - bes.main $* diff --git a/src/usage.sh b/src/usage.sh new file mode 100644 index 0000000..a4f50cc --- /dev/null +++ b/src/usage.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +bes.usage(){ + echo -e " ${Cusa}Usage :${Coff}\n + ${Ccom}\tBuild current project (overwrite existing build) + ${Cspe}\tbes-build ${Copt} + ${Ccom}\tBuild current project and backup existing build + ${Cspe}\tbes-build ${Copt}-b${Ctext}, ${Copt}backup + ${Ccom}\tInstall or update bes-build on specified BINDIR directory or in /etc/local/bin directory + ${Cspe}\tbes-build ${Copt}-i${Ctext}, ${Copt}install ${Copt}[ ${Ctext}BINDIR${Copt} ] + ${Ccom}\tDisplay program version + ${Cspe}\tbes-build ${Copt}-v${Ctext}, ${Copt}version + ${Ccom}\tDisplay this help + ${Cspe}\tbes-build ${Copt}-h${Ctext}, ${Copt}help" + + echo -e "${Coff}" +}