#1454 PR merged: Simplified UserInput return codes to the 'read' return code

Labels: cleanup, fixed / solved / done

jsmeix opened issue at 2017-08-24 17:53:

The UserInput return code is now simply 0 or 1:

The UserInput return code is the return code of
the 'read' bash builtin that is called to get user input.

When the UserInput function is called with right syntax
its return code is 0 for any actual user input and
in case of any (non empty) automated user input.

The return code is 1 when the 'read' call timed out
(i.e. when there was no actual user input)
so that one can distinguish between an explicitly
provided user input and no actual user input
even if the explicitly provided user input is the same
as the default so that it makes a difference
whether or not the user explicitly chose and confirmed
that the default is what he actually wants
or if he let things "just happen" inattentively via timeout
where it is important to have a big timeout
so that an attentive user will actively provide user input
to proceed even if it is same as the default.


The UserInput function logged already
whether or not its 'read' call timed out
but its various return codes were oversophisticated.

Now the UserInput function return code has a simple meaning:
0 means "real input" while 1 means "fallback/default".

Now in caller scipts code like

if input="$( UserInput ... )" ; then
    LogPrint "Got $input"
    LogPrint "Using default $input"

can be used if different behaviour is intended depending
on "real input" versus fallback/default behaviour.

jsmeix commented at 2017-08-25 11:21:

I have the "Avoid stderr ..." comments explicitly because of your
to show why in this case ReaR does rightfully destroy information
(here misleading information about possibly wrong bash coding).

I planned to clean up all '>/dev/null' usage in ReaR
(in particular both '1>/dev/null' and '2>/dev/null')
but until I have done this (which needs some time)
I need comments where a '>/dev/null' usage
is really right in ReaR.

[Export of Github issue for rear/rear.]