made user prompts more consistent

All direct uses of the 'read' builtin are now close to the following
format: possibly a block of statement text to the user output by
whatever means are handiest then, if not an 'anykey' prompt, a loop
which prompts and checks for valid input. The prompt is generally a
concise line in the forms of

    read -p "(A)pples or (O)ranges?: "
    read -n1 -p "Press any key to continue: "

Then a case statement handles the input in the format:

    A|a) apple_action ;;
    O|o) orange_action ;;
    *) unknown_response ;;

Also misc minor changes such as modifying wording or option letters,
changing linebreaks in case statements, etc.

Beyond simple wording changes in the statement text, there was also:

* remove_files(): removed the 'echo -e foo\n' which seemed unnecessary.
* use_options(): added the SAVEDOPT and QUEUEOPT variables which are
  used in read's prompt to customize it to the nature of the actually
  possible choices and removed the 'else's we don't need to display.
This commit is contained in:
slakmagik 2010-06-14 23:54:26 +00:00
parent a21d663040
commit 69224bfd1c

View file

@ -322,23 +322,30 @@ EOF
done done
cat << EOF cat << EOF
To have sbopkg create them, type 'y'. If these values are incorrect, press 'n' You can have sbopkg create them or, if these values are incorrect, you can
and edit your config files or pass different flags. abort to edit your config files or pass different flags.
EOF EOF
read -n1 -ep "[y/n] " while :; do
if [[ $REPLY == y ]]; then read $NFLAG -ep "(C)reate or (A)bort?: "
case $REPLY in
C|c)
if ! mkdir -p $DIRS2MK 2>/dev/null; then if ! mkdir -p $DIRS2MK 2>/dev/null; then
echo "$SCRIPT: failed to create directories" >&2 echo "$SCRIPT: failed to create directories" >&2
cleanup; exit 1 cleanup; exit 1
fi fi
else break
;;
A|a)
if [[ ${FUNCNAME[1]} == main ]]; then if [[ ${FUNCNAME[1]} == main ]]; then
cleanup; exit 1 cleanup; exit 1
else else
return 1 return 1
fi fi
fi ;;
*) unknown_response ;;
esac
done
fi fi
for ((i=0; i<${#DIR_VARS[*]}; i++)); do for ((i=0; i<${#DIR_VARS[*]}; i++)); do
@ -478,7 +485,7 @@ get_sbo_packages() {
--file $CONFIRMLIST 2> $REMOVELIST --file $CONFIRMLIST 2> $REMOVELIST
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
removepkg $(tr -d \" < $REMOVELIST) removepkg $(tr -d \" < $REMOVELIST)
read -n1 -p "Press any key to continue." read -n1 -ep "Press any key to continue: "
fi fi
fi fi
else else
@ -1282,7 +1289,7 @@ info_item() {
continue; continue;
fi fi
install_package $OUTPUT $CURPACKAGE | tee $TMPLOG install_package $OUTPUT $CURPACKAGE | tee $TMPLOG
read -n 1 -p "Press any key to continue." read -n1 -ep "Press any key to continue: "
if [[ $KEEPLOG ]]; then if [[ $KEEPLOG ]]; then
cat $TMPLOG >> $LOGFILE cat $TMPLOG >> $LOGFILE
fi fi
@ -2618,18 +2625,16 @@ read_info() {
if [[ $2 == --check_buildable ]]; then if [[ $2 == --check_buildable ]]; then
if [[ $DOWNLOAD == "UNSUPPORTED" || $DOWNLOAD == "UNTESTED" ]]; then if [[ $DOWNLOAD == "UNSUPPORTED" || $DOWNLOAD == "UNTESTED" ]]; then
while :; do
echo echo
crunch_fmt "$PRGNAM: This package is marked UNSUPPORTED \ crunch_fmt "$PRGNAM: This package is marked UNSUPPORTED \
or UNTESTED and may not build successfully on your \ or UNTESTED and may not build successfully on your \
architecture. Do you want to try and proceed anyway or \ architecture."
do you want to skip it?"
echo echo
echo "Press (Y)es to proceed or (N)o to skip." while :; do
read read $NFLAG -ep "(P)roceed anyway or (S)kip?: "
case $REPLY in case $REPLY in
y* | Y* ) break ;; P|p) break ;;
n* | N* ) return 1 ;; S|s) return 1 ;;
*) unknown_response ;; *) unknown_response ;;
esac esac
done done
@ -3080,14 +3085,13 @@ remove_files() {
else else
# Unquote file names # Unquote file names
tr -d \" < $FILES > $FILES_DELETING tr -d \" < $FILES > $FILES_DELETING
echo -e "[ Displaying $TOPIC ]\n" | echo "[ Displaying $TOPIC ]" | cat - $FILES_DELETING | $PAGER
cat - $FILES_DELETING | $PAGER
while :; do
echo echo
read -n1 -ep "Do you want to delete these files? [y/n] " while :; do
read $NFLAG -ep "(K)eep or (D)elete these files?: "
case $REPLY in case $REPLY in
n* | N* ) break ;; K|k) break ;;
y* | Y* ) DELETE=1; break ;; D|d) DELETE=1; break ;;
*) unknown_response ;; *) unknown_response ;;
esac esac
done done
@ -3162,16 +3166,15 @@ install_package() {
if [[ $(find $INSTDIR/$INSTPKG ! -user root -o ! -group root) ]]; then if [[ $(find $INSTDIR/$INSTPKG ! -user root -o ! -group root) ]]; then
crunch_fmt "WARNING: The file $INSTPKG is not set with root:root \ crunch_fmt "WARNING: The file $INSTPKG is not set with root:root \
permissions! Do you want to proceed? Here is the output of \ permissions! Here is the output of ls -l:"
ls -l:"
echo echo
ls -l $INSTDIR/$INSTPKG ls -l $INSTDIR/$INSTPKG
echo echo
while :; do while :; do
read -n1 -ep "Press (Y)es to proceed or (N)o to abort: " read $NFLAG -ep "(P)roceed anyway or (A)bort?: "
case $REPLY in case $REPLY in
y* | Y* ) echo "Proceeding..."; break ;; P|p) echo "Proceeding..."; break ;;
n* | N* ) echo "Aborting..."; return ;; A|a) echo "Aborting..."; return ;;
*) unknown_response ;; *) unknown_response ;;
esac esac
done done
@ -3306,9 +3309,7 @@ build_package() {
r* | R* ) # Retry r* | R* ) # Retry
continue 2 continue 2
;; ;;
* ) # Huh? *) unknown_response ;;
unknown_response
;;
esac esac
done done
fi fi
@ -3460,34 +3461,19 @@ pick_file() {
esac esac
done done
else else
while :; do
echo echo
crunch_fmt "A local $FILE file for $PKG was found in \ crunch_fmt "A local $FILE file for $PKG was found in \
addition to the original $FILE file." addition to the original $FILE file."
echo "Which one would you like to use?"
echo echo
crunch_fmt "(O)riginal, (L)ocal, (D)iff, (C)ancel:" while :; do
read read $NFLAG -ep \
"Use (O)riginal/(L)ocal, see (D)iff, or (C)ancel?: "
case $REPLY in case $REPLY in
o* | O* ) O|o) PICKFILE="original"; break ;;
PICKFILE="original" L|l) PICKFILE="local"; break ;;
break D|d) $PAGER $SBOPKGTMP/sbopkg_diff ;;
;; C|c) cleanup; return 1 ;;
l* | L* ) *) unknown_response ;;
PICKFILE="local"
break
;;
d* | D* )
$PAGER $SBOPKGTMP/sbopkg_diff
;;
c* | C* )
rm $SBOPKGTMP/sbopkg_diff
cleanup
return 1
;;
* ) # Huh?
unknown_response
;;
esac esac
done done
fi fi
@ -3514,7 +3500,7 @@ use_options() {
local OPTAPP=$2 local OPTAPP=$2
local OPTCHOICE=$SBOPKGTMP/sbopkg_options_choice local OPTCHOICE=$SBOPKGTMP/sbopkg_options_choice
local OPTLIST=$SBOPKGTMP/sbopkg_options_list local OPTLIST=$SBOPKGTMP/sbopkg_options_list
local TMPOPTIONS LDOPTIONS CHOICE OPTIONS_MSG REPLY local TMPOPTIONS LDOPTIONS CHOICE OPTIONS_MSG REPLY SAVEDOPT QUEUEOPT
# By default (i.e. no options.sbopkg file) there are no build options. # By default (i.e. no options.sbopkg file) there are no build options.
unset BUILDOPTIONS unset BUILDOPTIONS
@ -3558,29 +3544,24 @@ use_options() {
rm -f $OPTLIST $OPTCHOICE rm -f $OPTLIST $OPTCHOICE
fi fi
else else
while :; do echo
echo "One or more build option files for the $OPTAPP" echo "One or more build option files for the $OPTAPP"
echo "SlackBuild script were found:" echo "SlackBuild script were found:"
echo echo
if [[ $TMPOPTIONS ]]; then if [[ $TMPOPTIONS ]]; then
echo "Saved options: $TMPOPTIONS" echo "Saved options: $TMPOPTIONS"
else SAVEDOPT=" (S)aved,"
echo "Saved options: No saved build options found"
fi fi
if [[ $LDOPTIONS ]]; then if [[ $LDOPTIONS ]]; then
echo "Queuefile options: $LDOPTIONS" echo "Queuefile options: $LDOPTIONS"
else QUEUEOPT=" (Q)ueuefile,"
echo "Queuefile options: No queuefile options found"
fi fi
echo echo
crunch_fmt "Please choose (N)one, (S)aved, (Q)ueuefile, \ while :; do
or (A)bort" read $NFLAG -ep "Use (N)one,$SAVEDOPT$QUEUEOPT or (A)bort?: "
read
case $REPLY in case $REPLY in
n* | N* ) N|n) break ;;
break S|s)
;;
s* | S* )
if [[ $TMPOPTIONS ]]; then if [[ $TMPOPTIONS ]]; then
cp $PKGPATH/options.sbopkg $PKGPATH/options.build cp $PKGPATH/options.sbopkg $PKGPATH/options.build
BUILDOPTIONS=$TMPOPTIONS BUILDOPTIONS=$TMPOPTIONS
@ -3592,7 +3573,7 @@ use_options() {
echo echo
fi fi
;; ;;
q* | Q* ) Q|q)
if [[ $LDOPTIONS ]]; then if [[ $LDOPTIONS ]]; then
cp $SBOPKGTMP/sbopkg_"$OPTAPP"_loadoptions \ cp $SBOPKGTMP/sbopkg_"$OPTAPP"_loadoptions \
$PKGPATH/options.build $PKGPATH/options.build
@ -3605,13 +3586,8 @@ use_options() {
echo echo
fi fi
;; ;;
a* | A* ) A|a) return 1 ;;
return 1 *) unknown_response ;;
;;
* )
unknown_response
echo
;;
esac esac
done done
echo echo
@ -3763,7 +3739,6 @@ process_queue() {
return 0 return 0
fi fi
else else
while :; do
cat $TMPLOG cat $TMPLOG
echo echo
echo "Pre-check complete." echo "Pre-check complete."
@ -3772,20 +3747,16 @@ process_queue() {
results above? Packages not found will be skipped during \ results above? Packages not found will be skipped during \
the process." the process."
echo echo
echo "Press (Y)es to proceed or (N)o to quit." while :; do
read read $NFLAG -ep "(P)roceed or (Q)uit?: "
case $REPLY in case $REPLY in
y* | Y* ) P|p) break ;;
break Q|q)
;;
n* | N* )
rm -f $PKGPATH/$CHKBUILD.{info,SlackBuild}.build rm -f $PKGPATH/$CHKBUILD.{info,SlackBuild}.build
rm -f $PKGPATH/options.build rm -f $PKGPATH/options.build
return 0 return 0
;; ;;
* ) *) unknown_response ;;
unknown_response
;;
esac esac
done done
echo echo
@ -3872,7 +3843,7 @@ process_queue() {
echo >> $TMPLOG echo >> $TMPLOG
cat $TMPLOG cat $TMPLOG
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
read -n 1 -p "Press any key to continue." read -n1 -ep "Press any key to continue: "
fi fi
if [[ $KEEPLOG ]]; then if [[ $KEEPLOG ]]; then
cat $TMPLOG >> $LOGFILE cat $TMPLOG >> $LOGFILE
@ -3953,8 +3924,8 @@ check_for_latest() {
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
MSG="Different versions reported. Press <OK> to continue." MSG="Different versions reported. Press <OK> to continue."
else else
MSG="Different versions reported. Press (Y)es to \ MSG="Different versions reported. (D)ownload the remote \
download the update package or press (N)o to quit." package or (Q)uit?: "
fi fi
fi fi
else else
@ -3985,13 +3956,12 @@ check_for_latest() {
echo echo
echo "Latest version of sbopkg found on sbopkg.org: $NVRS" echo "Latest version of sbopkg found on sbopkg.org: $NVRS"
echo echo
crunch_fmt "$MSG"
if [[ $SBOPKGUP ]]; then if [[ $SBOPKGUP ]]; then
while :; do while :; do
read read $NFLAG -ep "$(crunch_fmt "$MSG")"
case $REPLY in case $REPLY in
y* | Y* ) break ;; D|d) break ;;
n* | N* ) return 0 ;; Q|q) return ;;
*) unknown_response ;; *) unknown_response ;;
esac esac
done done
@ -4019,7 +3989,7 @@ check_for_latest() {
\nhttp://www.sbopkg.org/changelog\ \nhttp://www.sbopkg.org/changelog\
\n" \n"
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
read -n 1 -p "Press any key to continue." read -n1 -ep "Press any key to continue: "
fi fi
fi fi
} }
@ -4375,6 +4345,8 @@ SBOVER=svn_r$(cut -d' ' -f2 <<< "$REV")
DIAG=1 DIAG=1
ON_ERROR=ask ON_ERROR=ask
REPOS_FIELDS=7 REPOS_FIELDS=7
# this is the undocumented 'slakmagik hates hitting enter' option
NFLAG=$NFLAG
# Make sure we are root. # Make sure we are root.
if [[ $(id -u) != 0 ]]; then if [[ $(id -u) != 0 ]]; then
@ -4612,21 +4584,14 @@ else
if [[ -r $QUEUEDIR/$PKGBUILD.sqf ]] && if [[ -r $QUEUEDIR/$PKGBUILD.sqf ]] &&
search_package $PKGBUILD; then search_package $PKGBUILD; then
crunch_fmt "Both a queuefile and a package were found with \ crunch_fmt "Both a queuefile and a package were found with \
the name \"$PKGBUILD\". Which would you like to use?" the name \"$PKGBUILD\"."
echo echo
echo "Please enter (Q)ueuefile, (P)ackage, or (A)bort:"
while :; do while :; do
read read $NFLAG -ep "Use (Q)ueuefile, (P)ackage, or (A)bort?: "
case $REPLY in case $REPLY in
q* | Q* ) parse_queue $QUEUEDIR/$PKGBUILD.sqf Q|q) parse_queue $QUEUEDIR/$PKGBUILD.sqf; break ;;
break P|p) add_item_to_queue $PKGBUILD; break ;;
;; A|a) cleanup; exit 1 ;;
p* | P* ) add_item_to_queue $PKGBUILD
break
;;
a* | A* ) cleanup
exit 1
;;
*) unknown_response ;; *) unknown_response ;;
esac esac
done done
@ -4671,12 +4636,11 @@ else
if [[ $PREVIEW_READMES ]]; then if [[ $PREVIEW_READMES ]]; then
view_queue_readmes view_queue_readmes
echo echo
echo "OK to continue processing?"
while :; do while :; do
read read $NFLAG -ep "(C)ontinue processing or (Q)uit?: "
case $REPLY in case $REPLY in
y* | Y* ) break ;; C|c) break ;;
n* | N* ) cleanup; exit 1 ;; Q|q) cleanup; exit 1 ;;
*) unknown_response ;; *) unknown_response ;;
esac esac
done done