enhance display + add usage

This commit is contained in:
a-sansara 2017-04-30 04:19:29 +02:00
parent ab999408d1
commit d3a63b09bd
5 changed files with 81 additions and 26 deletions

49
dist/bes-build vendored
View File

@ -9,7 +9,7 @@ bes.build(){
bes.echo.state $? bes.echo.state $?
fi fi
if [ -f "$APP_BIN" ]; then 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}" 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 mv $APP_BIN $APP_DIR/dist/$(date +%y%m%d)-$APP_NAME
else else
@ -22,23 +22,24 @@ bes.build(){
bes.echo.action "reading ${Coff}src/" bes.echo.action "reading ${Coff}src/"
for entry in "$APP_DIR/src"/*.sh; do for entry in "$APP_DIR/src"/*.sh; do
if [ "$(basename $entry)" != "main.sh" ]; then 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" tail -n +2 "$entry" >> "$APP_BIN"
fi fi
done done
if [ -f "$APP_DIR/src/main.sh" ]; then if [ -f "$APP_DIR/src/main.sh" ]; then
tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" 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 fi
bes.echo.state 0 bes.echo.state 0
bes.echo.action "set execution mode" bes.echo.action "set execution mode"
chmod +x $APP_BIN chmod +x $APP_BIN
bes.echo.state $? done=$?
bes.echo.state $done
bes.echo.rs $done
else else
bes.echo.error "no src/ directory. exit" bes.echo.error "no src/ directory. exit"
bes.echo.state 1 bes.echo.state 1
fi fi
echo
} }
BES_TERM_WIDTH=105 BES_TERM_WIDTH=105
@ -63,7 +64,7 @@ bes.echo(){
local isAction=${2:-'0'} local isAction=${2:-'0'}
local symbol=${3:-' *'} local symbol=${3:-' *'}
if [ ! "$BES_NOCOLOR" = 1 ]; then if [ ! "$BES_NOCOLOR" = 1 ]; then
local c=$Cok local c=" "
if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then
c=$Caction c=$Caction
fi fi
@ -106,6 +107,15 @@ bes.echo.state(){
fi 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(){ bes.echo.error(){
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n" echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
} }
@ -168,24 +178,41 @@ bes.install(){
fi 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 BES_BUILD_VERSION=0.3
APP_DIR=$(pwd) APP_DIR=$(pwd)
APP_NAME=$(basename $(pwd)) APP_NAME=$(basename $(pwd))
APP_BIN=$APP_DIR/dist/$APP_NAME APP_BIN=$APP_DIR/dist/$APP_NAME
bes.main(){ bes.main(){
if [ "$1" = "version" ]; then if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
echo $BES_BUILD_VERSION echo $BES_BUILD_VERSION
else else
bes.title 'bes-build' $BES_BUILD_VERSION bes.title 'bes-build' $BES_BUILD_VERSION
echo echo
if [ "$1" = "install" ]; then if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
bes.install $2 bes.install "$2"
elif [ -z "$1" ] || [ "$1" = "-s" ]; then elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then
bes.usage
elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then
bes.build "$1" bes.build "$1"
fi fi
echo echo
fi fi
} }
bes.main $* bes.main $*

View File

@ -9,7 +9,7 @@ bes.build(){
bes.echo.state $? bes.echo.state $?
fi fi
if [ -f "$APP_BIN" ]; then 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}" 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 mv $APP_BIN $APP_DIR/dist/$(date +%y%m%d)-$APP_NAME
else else
@ -22,21 +22,22 @@ bes.build(){
bes.echo.action "reading ${Coff}src/" bes.echo.action "reading ${Coff}src/"
for entry in "$APP_DIR/src"/*.sh; do for entry in "$APP_DIR/src"/*.sh; do
if [ "$(basename $entry)" != "main.sh" ]; then 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" tail -n +2 "$entry" >> "$APP_BIN"
fi fi
done done
if [ -f "$APP_DIR/src/main.sh" ]; then if [ -f "$APP_DIR/src/main.sh" ]; then
tail -n +2 "$APP_DIR/src/main.sh" >> "$APP_BIN" 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 fi
bes.echo.state 0 bes.echo.state 0
bes.echo.action "set execution mode" bes.echo.action "set execution mode"
chmod +x $APP_BIN chmod +x $APP_BIN
bes.echo.state $? done=$?
bes.echo.state $done
bes.echo.rs $done
else else
bes.echo.error "no src/ directory. exit" bes.echo.error "no src/ directory. exit"
bes.echo.state 1 bes.echo.state 1
fi fi
echo
} }

View File

@ -22,7 +22,7 @@ bes.echo(){
local isAction=${2:-'0'} local isAction=${2:-'0'}
local symbol=${3:-' *'} local symbol=${3:-' *'}
if [ ! "$BES_NOCOLOR" = 1 ]; then if [ ! "$BES_NOCOLOR" = 1 ]; then
local c=$Cok local c=" "
if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then
c=$Caction c=$Caction
fi fi
@ -65,6 +65,15 @@ bes.echo.state(){
fi 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(){ bes.echo.error(){
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n" echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
} }

View File

@ -6,18 +6,19 @@ BES_BUILD_VERSION=0.3
APP_BIN=$APP_DIR/dist/$APP_NAME APP_BIN=$APP_DIR/dist/$APP_NAME
bes.main(){ bes.main(){
if [ "$1" = "version" ]; then if [ "$1" = "version" ] || [ "$1" = "-v" ]; then
echo $BES_BUILD_VERSION echo $BES_BUILD_VERSION
else else
bes.title 'bes-build' $BES_BUILD_VERSION bes.title 'bes-build' $BES_BUILD_VERSION
echo echo
if [ "$1" = "install" ]; then if [ "$1" = "install" ] || [ "$1" = "-i" ]; then
bes.install $2 bes.install "$2"
elif [ -z "$1" ] || [ "$1" = "-s" ]; then elif [ "$1" = "help" ] || [ "$1" = "-h" ]; then
bes.usage
elif [ -z "$1" ] || [ "$1" = "backup" ] || [ "$1" = "-b" ]; then
bes.build "$1" bes.build "$1"
fi fi
echo echo
fi fi
} }
bes.main $* bes.main $*

17
src/usage.sh Normal file
View File

@ -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}"
}