mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 18:12:50 +08:00
feat(console): 添加 --force-force 参数以跳过所有交互确认
This commit is contained in:
34
extend/base/common/console/InputBase.php
Normal file
34
extend/base/common/console/InputBase.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace base\common\console;
|
||||
|
||||
use think\console\Input;
|
||||
|
||||
class InputBase extends Input
|
||||
{
|
||||
public function __construct($argv = null)
|
||||
{
|
||||
if (null === $argv) {
|
||||
$argv = $_SERVER['argv'];
|
||||
array_shift($argv);
|
||||
}
|
||||
|
||||
$argv = $this->normalizeTokens($argv);
|
||||
|
||||
parent::__construct($argv);
|
||||
}
|
||||
|
||||
protected function normalizeTokens(array $tokens): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($tokens as $token) {
|
||||
if ($token === '-ff') {
|
||||
$result[] = '--force-force';
|
||||
continue;
|
||||
}
|
||||
$result[] = $token;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
35
extend/base/common/console/OutputBase.php
Normal file
35
extend/base/common/console/OutputBase.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace base\common\console;
|
||||
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class OutputBase extends Output
|
||||
{
|
||||
public function confirm(Input $input, $question, $default = true)
|
||||
{
|
||||
$question = $this->appendForceForceTip($question);
|
||||
|
||||
if ($this->isForceForceEnabled($input)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::confirm($input, $question, $default);
|
||||
}
|
||||
|
||||
protected function isForceForceEnabled(Input $input): bool
|
||||
{
|
||||
return (bool) $input->getOption('force-force');
|
||||
}
|
||||
|
||||
protected function appendForceForceTip($question): string
|
||||
{
|
||||
$tip = '<comment>(您可以追加 --force-force 或 -ff 参数重新运行以跳过所有交互确认)</comment>';
|
||||
if (is_string($question) && $question !== '') {
|
||||
return rtrim($question) . ' ' . $tip;
|
||||
}
|
||||
|
||||
return $tip;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user