Skip to content

Commit

Permalink
Merge pull request #3 from inhere/master
Browse files Browse the repository at this point in the history
update: add a util class. some modify ...
  • Loading branch information
inhere authored Mar 14, 2018
2 parents 3510373 + edaefac commit 6348c3b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private function indexComamnd(string $className)
'Usage:' => [ \input()->getCommand() . ':{command} [arguments] [options]'],
'Commands:' => $methodCommands,
'Options:' => [
'-h,--help' => 'Show help of the command group or specified command action',
'-h, --help' => 'Show help of the command group or specified command action',
],
];

Expand Down Expand Up @@ -186,8 +186,8 @@ private function showCommandList()
$commandList['Usage:'] = ["php $script"];
$commandList['Commands:'] = $commands;
$commandList['Options:'] = [
'-v,--version' => 'show version',
'-h,--help' => 'show help',
'-h, --help' => 'show help information',
'-v, --version' => 'show version',
];

// show logo
Expand Down
53 changes: 53 additions & 0 deletions src/Helper/ConsoleUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Created by PhpStorm.
* User: inhere
* Date: 2018/3/14
* Time: 下午3:21
*/

namespace Swoft\Console\Helper;

/**
* Class ConsoleUtil
* @package Swoft\Console\Helper
*/
class ConsoleUtil
{
/**
* 确认, 发出信息要求确认
* @param string $question 发出的信息
* @param bool $default Default value
* @return bool
*/
public static function confirm(string $question, $default = true): bool
{
if (!$question = trim($question)) {
\output()->writeln('Please provide a question message!', true, 2);
}

$question = ucfirst(trim($question, '?'));
$default = (bool)$default;
$defaultText = $default ? 'yes' : 'no';
$message = "<comment>$question ?</comment>\nPlease confirm (yes|no)[default:<info>$defaultText</info>]: ";

while (true) {
\output()->writeln($message, false);
$answer = \input()->read();

if (empty($answer)) {
return $default;
}

if (0 === stripos($answer, 'y')) {
return true;
}

if (0 === stripos($answer, 'n')) {
return false;
}
}

return false;
}
}

0 comments on commit 6348c3b

Please sign in to comment.