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

53
dist/bes-build vendored
View File

@ -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 $*

View File

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

View File

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

View File

@ -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 $*

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