mbland / go-script-bash

Framework for writing modular, discoverable, testable Bash scripts
ISC License
95 stars 16 forks source link

Adds 'required' option to 'prompt_for_input' #237

Open nkakouros opened 6 years ago

nkakouros commented 6 years ago

cc: @mbland

This PR adds an extra argument to @go.prompt_for_input. If the function is called with this argument, eg @go.prompt_for_input 'variable' 'prompt' '' '' 'required' and the user supplies no value, ie presses only enter, the prompt will reappear until the user actually supplies something. If instead of required another value is supplied, the behavior is the already existing one.

The rational behind this PR is that as it stands now, using @go.prompt_for_input in a loop to force the user to actually submit sth, is exactly identical to using read directly. It saves nothing. With this PR, it only takes one line and you are sure that the user will provide some input. Moreover, @go.prompt_for_yes_or_no already loops until the user supplies something. This PR makes the two functions more "feature compatible".

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.007%) to 95.004% when pulling 78d77b3b2008715eca5b3d5305caba31a880c712 on tterranigma:prompt into 292e0803074eb538ab8633a657c53d3a975ba922 on mbland:master.