add input functions
This commit is contained in:
parent
92c0fa289d
commit
2e1ef46ec6
2 changed files with 58 additions and 13 deletions
28
sf
28
sf
|
|
@ -32,6 +32,22 @@ function sfwarn {
|
|||
echo -e "${sftbf}${sfty}WARNING${sftrs} $1"
|
||||
}
|
||||
|
||||
# Public input functions
|
||||
function sfask {
|
||||
if [ "$2" == "" ]; then
|
||||
read -p "$1? [Y/n] " sfin
|
||||
[[ "$sfin" =~ y|Y|^$ ]] && sfin=true || sfin=false
|
||||
else
|
||||
read -p "$1? [y/N] " sfin
|
||||
[[ "$sfin" =~ n|N|^$ ]] && sfin=false || sfin=true
|
||||
fi
|
||||
}
|
||||
|
||||
function sfget {
|
||||
[ "$2" != "" ] && read -p "$1 [$2]: " sfin || read -p "$1: " sfin
|
||||
[ "$sfin" == "" ] && [ "$2" != "" ] && sfin="$2"
|
||||
}
|
||||
|
||||
# Internal error function
|
||||
function _sferr {
|
||||
echo -e "${sftbf}${sftr}SF PARSE ERROR${sftrs} $1"
|
||||
|
|
@ -128,13 +144,9 @@ IFS=$OLDIFS
|
|||
# Usage function
|
||||
function _sfusage {
|
||||
echo -n "Usage: $(basename $0)"
|
||||
if [ "$_sfodesc" != "" ]; then
|
||||
echo -n " [OPTIONS]"
|
||||
fi
|
||||
[ "$_sfodesc" != "" ] && echo -n " [OPTIONS]"
|
||||
echo -e "$_sfphead"
|
||||
if [ ! -z ${sfdesc+x} ]; then
|
||||
echo -e "\n$sfdesc"
|
||||
fi
|
||||
[ ! -z ${sfdesc+x} ] && echo -e "\n$sfdesc"
|
||||
if [ "$_sfpdesc" != "" ]; then
|
||||
echo -e "\nPOSITIONAL ARGUMENTS"
|
||||
echo -e "$_sfpdesc" | column -c 80 -s ";" -t -W 2
|
||||
|
|
@ -156,9 +168,7 @@ function _sfusage {
|
|||
# Check for help flag
|
||||
for a in "$@"; do
|
||||
# Check if help flag ist set
|
||||
if [ "$a" == "-h" ] || [ "$a" == "--help" ]; then
|
||||
_sfusage
|
||||
fi
|
||||
[ "$a" == "-h" ] || [ "$a" == "--help" ] && _sfusage
|
||||
done
|
||||
|
||||
# Parse arguments
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue