Skip to content

Commit 1f8f94d

Browse files
committed
prompt password input use sh instead bash
1 parent b934322 commit 1f8f94d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/Utils/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public static function dumpVars(...$args): string
367367
var_dump(...$args);
368368
$string = ob_get_clean();
369369

370-
return preg_replace("/=>\n\s+/", '=> ', $string);
370+
return preg_replace("/=>\n\s+/", '=> ', trim($string));
371371
}
372372

373373
/**
@@ -383,6 +383,6 @@ public static function printVars(...$args): string
383383
$string .= print_r($arg, 1) . PHP_EOL;
384384
}
385385

386-
return preg_replace("/Array\n\s+\(/", 'Array (', $string);
386+
return preg_replace("/Array\n\s+\(/", 'Array (', trim($string));
387387
}
388388
}

src/Utils/Interact.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function read($message = null, $nl = false, array $opts = []): str
5555
/**
5656
* alias of the `select()`
5757
* @param string $description 说明
58-
* @param mixed $options 选项数据
58+
* @param string|array $options 选项数据
5959
* e.g
6060
* [
6161
* // option => value
@@ -66,7 +66,7 @@ public static function read($message = null, $nl = false, array $opts = []): str
6666
* @param bool $allowExit 有退出选项 默认 true
6767
* @return string
6868
*/
69-
public static function select($description, $options, $default = null, $allowExit = true): string
69+
public static function select(string $description, $options, $default = null, $allowExit = true): string
7070
{
7171
return self::choice($description, $options, $default, $allowExit);
7272
}
@@ -79,7 +79,7 @@ public static function select($description, $options, $default = null, $allowExi
7979
* @param bool $allowExit
8080
* @return string
8181
*/
82-
public static function choice($description, $options, $default = null, $allowExit = true): string
82+
public static function choice(string $description, $options, $default = null, $allowExit = true): string
8383
{
8484
if (!$description = trim($description)) {
8585
self::error('Please provide a description text!', 1);
@@ -278,7 +278,7 @@ public static function ask(string $question, $default = null, \Closure $validato
278278
* @param \Closure|null $validator Validator, must return bool.
279279
* @return null|string
280280
*/
281-
public static function question($question, $default = null, \Closure $validator = null)
281+
public static function question(string $question, $default = null, \Closure $validator = null)
282282
{
283283
if (!$question = trim($question)) {
284284
self::error('Please provide a question text!', 1);
@@ -350,7 +350,7 @@ public static function question($question, $default = null, \Closure $validator
350350
* @param int $times Allow input times
351351
* @return string|null
352352
*/
353-
public static function limitedAsk(string $question, $default = null, \Closure $validator = null, $times = 3)
353+
public static function limitedAsk(string $question, $default = null, \Closure $validator = null, int $times = 3)
354354
{
355355
if (!$question = trim($question)) {
356356
self::error('Please provide a question text!', 1);
@@ -360,7 +360,7 @@ public static function limitedAsk(string $question, $default = null, \Closure $v
360360
$answer = '';
361361
$question = ucfirst($question);
362362
$hasDefault = null !== $default;
363-
$back = $times = ((int)$times > 6 || $times < 1) ? 3 : (int)$times;
363+
$back = $times = ($times > 6 || $times < 1) ? 3 : $times;
364364

365365
if ($hasDefault) {
366366
$message = "<comment>{$question}</comment>(default: <info>$default</info>) ";
@@ -402,7 +402,11 @@ public static function limitedAsk(string $question, $default = null, \Closure $v
402402
return $default;
403403
}
404404

405-
self::write("\n You've entered incorrectly <danger>$back</danger> times in a row. exit!", true, 1);
405+
self::write(
406+
"\n You've entered incorrectly <danger>$back</danger> times in a row. exit!",
407+
true,
408+
1
409+
);
406410
}
407411

408412
return $answer;
@@ -430,9 +434,9 @@ public static function promptSilent(string $prompt = 'Enter Password:'): string
430434
// $shell = 'echo $0';
431435

432436
// linux, unix, git-bash
433-
if (CliUtil::bashIsAvailable()) {
434-
// COMMAND: bash -c 'read -p "Enter Password:" -s user_input && echo $user_input'
435-
$command = sprintf('bash -c "read -p \'%s\' -s user_input && echo $user_input"', $prompt);
437+
if (CliUtil::shIsAvailable()) {
438+
// COMMAND: sh -c 'read -p "Enter Password:" -s user_input && echo $user_input'
439+
$command = sprintf('sh -c "read -p \'%s\' -s user_input && echo $user_input"', $prompt);
436440
$password = CliUtil::runCommand($command, false);
437441

438442
echo "\n";

0 commit comments

Comments
 (0)