Skip to content

Commit ba69f2e

Browse files
committed
breaking: remove more unused input methods
1 parent 0350a91 commit ba69f2e

File tree

12 files changed

+41
-345
lines changed

12 files changed

+41
-345
lines changed

examples/Controller/HomeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function colorCheckCommand(): void
204204
*/
205205
public function artFontCommand(FlagsParser $fs): int
206206
{
207-
$name = $this->input->getLongOpt('font', '404');
207+
$name = $fs->getOpt('font', '404');
208208

209209
if (!ArtFont::isInternalFont($name)) {
210210
return $this->output->liteError("Your input font name: $name, is not exists. Please use '-h' see allowed.");

src/Concern/ApplicationHelpTrait.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
use function ksort;
3535
use function sprintf;
3636
use function str_replace;
37-
use function strpos;
3837
use function strtr;
3938
use const PHP_EOL;
4039
use const PHP_OS;
@@ -174,14 +173,13 @@ public function showHelpInfo(string $command = ''): void
174173
*/
175174
public function showCommandList(): void
176175
{
177-
/** @var Input $input */
178-
$input = $this->input;
176+
$flags = $this->flags;
179177
// has option: --auto-completion
180-
$autoComp = $input->getOpt('auto-completion');
178+
$autoComp = $flags->getOpt('auto-completion');
181179
// has option: --shell-env
182-
$shellEnv = (string)$input->getLongOpt('shell-env', '');
180+
$shellEnv = $flags->getOpt('shell-env');
183181
// input is an path: /bin/bash
184-
if ($shellEnv && strpos($shellEnv, '/') !== false) {
182+
if ($shellEnv && str_contains($shellEnv, '/')) {
185183
$shellEnv = basename($shellEnv);
186184
}
187185

@@ -193,13 +191,11 @@ public function showCommandList(): void
193191

194192
$this->logf(Console::VERB_DEBUG, 'Display the application commands list');
195193

196-
$router = $this->getRouter();
197-
198-
$hasGroup = $hasCommand = false;
199-
$groupArr = $commandArr = [];
200-
$placeholder = 'No description of the command';
194+
$hasGroup = $hasCommand = false;
195+
$groupArr = $commandArr = [];
201196

202197
// all console groups/controllers
198+
$router = $this->getRouter();
203199
if ($groups = $router->getControllers()) {
204200
$hasGroup = true;
205201
ksort($groups);
@@ -217,6 +213,7 @@ public function showCommandList(): void
217213
$commandArr[] = PHP_EOL . '- <bold>Alone Commands</bold>';
218214
}
219215

216+
$placeholder = 'No description of the command';
220217
foreach ($groups as $name => $info) {
221218
$options = $info['options'];
222219
$controller = $info['handler'];
@@ -319,7 +316,7 @@ protected function dumpAutoCompletion(string $shellEnv, array $data): void
319316

320317
// info
321318
$glue = ' ';
322-
$genFile = $input->getOpt('gen-file', 'none');
319+
$genFile = $this->flags->getOpt('gen-file', 'none');
323320
$tplDir = dirname(__DIR__, 2) . '/resource/templates';
324321

325322
if ($shellEnv === 'bash') {
@@ -341,7 +338,7 @@ protected function dumpAutoCompletion(string $shellEnv, array $data): void
341338
}
342339

343340
// new: support custom tpl file for gen completion script
344-
$userTplFile = $input->getOpt('tpl-file');
341+
$userTplFile = $this->flags->getOpt('tpl-file');
345342
if ($userTplFile && file_exists($userTplFile)) {
346343
$tplFile = $userTplFile;
347344
}

src/Concern/AttachApplicationTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public function isInteractive(): bool
9191
return $this->app->isInteractive();
9292
}
9393

94-
$value = $this->input->getOpt(GlobalOption::NO_INTERACTIVE);
95-
return $value === false;
94+
// $value = $this->input->getOpt(GlobalOption::NO_INTERACTIVE);
95+
return $this->input->isInteractive();
9696
}
9797

9898
/**
@@ -106,7 +106,9 @@ public function getVerbLevel(): int
106106
return $this->app->getVerbLevel();
107107
}
108108

109-
return (int)$this->input->getLongOpt('debug', Console::VERB_ERROR);
109+
// return (int)$this->input->getLongOpt('debug', Console::VERB_ERROR);
110+
$envVal = OS::getEnvStrVal(Console::DEBUG_ENV_KEY);
111+
return $envVal !== '' ? (int)$envVal : Console::VERB_ERROR;
110112
}
111113

112114
/**

src/Concern/InputArgumentsTrait.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Concern/InputOptionsTrait.php

Lines changed: 0 additions & 120 deletions
This file was deleted.

src/Contract/InputInterface.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@
1616
*/
1717
interface InputInterface
1818
{
19-
// fixed args and opts for a command/controller-command
20-
public const ARG_REQUIRED = 1;
21-
22-
public const ARG_OPTIONAL = 2;
23-
24-
public const ARG_IS_ARRAY = 4;
25-
26-
public const OPT_BOOLEAN = 1; // eq symfony InputOption::VALUE_NONE
27-
28-
public const OPT_REQUIRED = 2;
29-
30-
public const OPT_OPTIONAL = 4;
31-
32-
public const OPT_IS_ARRAY = 8;
33-
3419
/**
3520
* 读取输入信息
3621
*
@@ -51,24 +36,6 @@ public function getScriptFile(): string;
5136
*/
5237
public function getCommand(): string;
5338

54-
/**
55-
* @return array
56-
*/
57-
public function getArgs(): array;
58-
59-
/**
60-
* @return array
61-
*/
62-
public function getOpts(): array;
63-
64-
/**
65-
* @param string $name
66-
* @param null $default
67-
*
68-
* @return bool|mixed|null
69-
*/
70-
public function getOpt(string $name, $default = null);
71-
7239
/**
7340
* Whether the stream is an interactive terminal
7441
*/

src/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function doRun(array $args)
279279

280280
$command = $first;
281281
array_shift($args);
282-
$this->input->popFirstArg();
282+
// $this->input->popFirstArg();
283283
}
284284

285285
// update subcommand

src/GlobalOption.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,42 @@ class GlobalOption
5050
* @psalm-var array<string, string>
5151
*/
5252
private static $options = [
53-
'--debug' => [
53+
'debug' => [
5454
'type' => FlagType::INT,
5555
'desc' => 'Setting the runtime log debug level(quiet 0 - 5 crazy)',
5656
'envVar' => Console::DEBUG_ENV_KEY,
5757
],
58-
'--ishell' => 'bool;Run application an interactive shell environment',
59-
'--profile' => 'bool;Display timing and memory usage information',
60-
'--no-color' => 'bool;Disable color/ANSI for message output',
61-
'--help' => 'bool;Display application help message;;;h',
62-
'--version' => 'bool;Show application version information;;;V',
63-
'--no-interactive' => 'bool;Run commands in a non-interactive environment',
64-
'--auto-completion' => [
58+
'ishell' => 'bool;Run application an interactive shell environment',
59+
'profile' => 'bool;Display timing and memory usage information',
60+
'no-color' => 'bool;Disable color/ANSI for message output',
61+
'help' => 'bool;Display application help message;;;h',
62+
'version' => 'bool;Show application version information;;;V',
63+
'no-interactive' => 'bool;Run commands in a non-interactive environment',
64+
// - hidden options
65+
'auto-completion' => [
6566
'type' => FlagType::BOOL,
6667
'hidden' => true,
6768
'desc' => 'Open generate auto completion script',
6869
// 'envVar' => Console::DEBUG_ENV_KEY,
6970
],
70-
'--shell-env' => [
71+
'shell-env' => [
7172
'type' => FlagType::STRING,
7273
'hidden' => true,
7374
'desc' => 'The shell env name for generate auto completion script',
7475
// 'envVar' => Console::DEBUG_ENV_KEY,
75-
'default' => 'stdout',
7676
],
77-
'--gen-file' => [
77+
'gen-file' => [
7878
'type' => FlagType::STRING,
7979
'hidden' => true,
8080
'desc' => 'The output file for generate auto completion script',
8181
// 'envVar' => Console::DEBUG_ENV_KEY,
82+
'default' => 'stdout',
83+
],
84+
'tpl-file' => [
85+
'type' => FlagType::STRING,
86+
'hidden' => true,
87+
'desc' => 'custom tpl file for generate completion script',
88+
// 'default' => 'stdout',
8289
],
8390
];
8491

0 commit comments

Comments
 (0)