LScli : add confirm helper method

This commit is contained in:
Benjamin Renard 2020-05-08 20:33:42 +02:00
parent 0d916d3d0d
commit 1de6d1d25e

View file

@ -295,6 +295,27 @@ class LScli extends LSlog_staticLoggerClass {
return array($return_value, $stdout, $stderr); return array($return_value, $stdout, $stderr);
} }
/**
* CLI helper to ask for user confirmation
*
* @param[in] $question string The confirmation question (optional, default: "Are you sure?")
*
* @retval boolean True if user confirmed, false otherwise
**/
public static function confirm($question=null) {
if (is_null($question))
$question = "Are you sure?";
echo "\n$question Type 'yes' to continue: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes'){
echo "User cancel\n";
return false;
}
echo "\n";
return true;
}
} }
/* /*