slitaz-base-files diff doc/libtaz.txt @ rev 317

libtaz.sh: add die() and im(), rework confirm().
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Jan 08 11:09:57 2017 +0200 (2017-01-08)
parents cca198d5952c
children f27c696b0f9e
line diff
     1.1 --- a/doc/libtaz.txt	Thu Dec 03 04:59:59 2015 +0200
     1.2 +++ b/doc/libtaz.txt	Sun Jan 08 11:09:57 2017 +0200
     1.3 @@ -25,6 +25,8 @@
     1.4  	emsg <string>         Output mark up messages
     1.5  	check_root            Check if user is logged as root
     1.6  	debug <string>        Display a DEBUG message when --debug is used
     1.7 +	die <string>          Report error and finish work
     1.8 +	im                    Returns true if you're in the interactive mode
     1.9  	confirm               Read answer to confirm an action
    1.10  	log <string>          Log activity, $activity must be set
    1.11  	optlist <lines>       Prints two-column list (of options, or functions, etc.)
    1.12 @@ -66,8 +68,34 @@
    1.13  
    1.14  	debug "A='$A'"
    1.15  
    1.16 -	echo -n "The question"; confirm
    1.17 -	confirm "The question (y/N)?"
    1.18 +	die 'Config %s absent. Exit' $config
    1.19 +
    1.20 +
    1.21 +	Using confirm()
    1.22 +	Use global options for auto-answering: '--yes' or '--noconfirm'.
    1.23 +	Use global option '--timeout' to define the wait time (default is 30 s).
    1.24 +	The letters "y", "Y", "n" and "N", used in the response, are localized.
    1.25 +	1. Outdated syntax. No options. Displays translated " [y/N] ? " and waits
    1.26 +	   for your input.
    1.27 +	   Answer formula is "[y/N]": to answer "yes" you need to enter "y" (or "Y"),
    1.28 +	   while to answer "no" you may enter "n" or "N" or any other letter, or
    1.29 +	   even just press Enter.
    1.30 +
    1.31 +	   echo -n "The question"; confirm && echo "Confirmed"
    1.32 +
    1.33 +	2. New syntax. Option is the string displayed. Answer formula the same.
    1.34 +
    1.35 +	   confirm "The question [y/N]?" && echo "Confirmed"
    1.36 +
    1.37 +	3. Modern syntax. Two options: the question and the preferred answer.
    1.38 +	   Displays the question and then translated answer formula as "[Y/n]" or
    1.39 +	   "[y/N]" depending on the preferred answer.
    1.40 +
    1.41 +	   confirm "The question?" y && echo "Confirmed"
    1.42 +
    1.43 +	In all cases, it returns "true" if you answer "yes", while returns "false"
    1.44 +	otherwise.
    1.45 +
    1.46  
    1.47  	activity='/var/log/my.log'
    1.48  	log "Message"