Skip to content

Commit

Permalink
breaking: remove more unused input methods
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 24, 2021
1 parent 0350a91 commit ba69f2e
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 345 deletions.
2 changes: 1 addition & 1 deletion examples/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function colorCheckCommand(): void
*/
public function artFontCommand(FlagsParser $fs): int
{
$name = $this->input->getLongOpt('font', '404');
$name = $fs->getOpt('font', '404');

if (!ArtFont::isInternalFont($name)) {
return $this->output->liteError("Your input font name: $name, is not exists. Please use '-h' see allowed.");
Expand Down
23 changes: 10 additions & 13 deletions src/Concern/ApplicationHelpTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use function ksort;
use function sprintf;
use function str_replace;
use function strpos;
use function strtr;
use const PHP_EOL;
use const PHP_OS;
Expand Down Expand Up @@ -174,14 +173,13 @@ public function showHelpInfo(string $command = ''): void
*/
public function showCommandList(): void
{
/** @var Input $input */
$input = $this->input;
$flags = $this->flags;
// has option: --auto-completion
$autoComp = $input->getOpt('auto-completion');
$autoComp = $flags->getOpt('auto-completion');
// has option: --shell-env
$shellEnv = (string)$input->getLongOpt('shell-env', '');
$shellEnv = $flags->getOpt('shell-env');
// input is an path: /bin/bash
if ($shellEnv && strpos($shellEnv, '/') !== false) {
if ($shellEnv && str_contains($shellEnv, '/')) {
$shellEnv = basename($shellEnv);
}

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

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

$router = $this->getRouter();

$hasGroup = $hasCommand = false;
$groupArr = $commandArr = [];
$placeholder = 'No description of the command';
$hasGroup = $hasCommand = false;
$groupArr = $commandArr = [];

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

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

// info
$glue = ' ';
$genFile = $input->getOpt('gen-file', 'none');
$genFile = $this->flags->getOpt('gen-file', 'none');
$tplDir = dirname(__DIR__, 2) . '/resource/templates';

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

// new: support custom tpl file for gen completion script
$userTplFile = $input->getOpt('tpl-file');
$userTplFile = $this->flags->getOpt('tpl-file');
if ($userTplFile && file_exists($userTplFile)) {
$tplFile = $userTplFile;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Concern/AttachApplicationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function isInteractive(): bool
return $this->app->isInteractive();
}

$value = $this->input->getOpt(GlobalOption::NO_INTERACTIVE);
return $value === false;
// $value = $this->input->getOpt(GlobalOption::NO_INTERACTIVE);
return $this->input->isInteractive();
}

/**
Expand All @@ -106,7 +106,9 @@ public function getVerbLevel(): int
return $this->app->getVerbLevel();
}

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

/**
Expand Down
45 changes: 0 additions & 45 deletions src/Concern/InputArgumentsTrait.php

This file was deleted.

120 changes: 0 additions & 120 deletions src/Concern/InputOptionsTrait.php

This file was deleted.

33 changes: 0 additions & 33 deletions src/Contract/InputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@
*/
interface InputInterface
{
// fixed args and opts for a command/controller-command
public const ARG_REQUIRED = 1;

public const ARG_OPTIONAL = 2;

public const ARG_IS_ARRAY = 4;

public const OPT_BOOLEAN = 1; // eq symfony InputOption::VALUE_NONE

public const OPT_REQUIRED = 2;

public const OPT_OPTIONAL = 4;

public const OPT_IS_ARRAY = 8;

/**
* 读取输入信息
*
Expand All @@ -51,24 +36,6 @@ public function getScriptFile(): string;
*/
public function getCommand(): string;

/**
* @return array
*/
public function getArgs(): array;

/**
* @return array
*/
public function getOpts(): array;

/**
* @param string $name
* @param null $default
*
* @return bool|mixed|null
*/
public function getOpt(string $name, $default = null);

/**
* Whether the stream is an interactive terminal
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function doRun(array $args)

$command = $first;
array_shift($args);
$this->input->popFirstArg();
// $this->input->popFirstArg();
}

// update subcommand
Expand Down
29 changes: 18 additions & 11 deletions src/GlobalOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,42 @@ class GlobalOption
* @psalm-var array<string, string>
*/
private static $options = [
'--debug' => [
'debug' => [
'type' => FlagType::INT,
'desc' => 'Setting the runtime log debug level(quiet 0 - 5 crazy)',
'envVar' => Console::DEBUG_ENV_KEY,
],
'--ishell' => 'bool;Run application an interactive shell environment',
'--profile' => 'bool;Display timing and memory usage information',
'--no-color' => 'bool;Disable color/ANSI for message output',
'--help' => 'bool;Display application help message;;;h',
'--version' => 'bool;Show application version information;;;V',
'--no-interactive' => 'bool;Run commands in a non-interactive environment',
'--auto-completion' => [
'ishell' => 'bool;Run application an interactive shell environment',
'profile' => 'bool;Display timing and memory usage information',
'no-color' => 'bool;Disable color/ANSI for message output',
'help' => 'bool;Display application help message;;;h',
'version' => 'bool;Show application version information;;;V',
'no-interactive' => 'bool;Run commands in a non-interactive environment',
// - hidden options
'auto-completion' => [
'type' => FlagType::BOOL,
'hidden' => true,
'desc' => 'Open generate auto completion script',
// 'envVar' => Console::DEBUG_ENV_KEY,
],
'--shell-env' => [
'shell-env' => [
'type' => FlagType::STRING,
'hidden' => true,
'desc' => 'The shell env name for generate auto completion script',
// 'envVar' => Console::DEBUG_ENV_KEY,
'default' => 'stdout',
],
'--gen-file' => [
'gen-file' => [
'type' => FlagType::STRING,
'hidden' => true,
'desc' => 'The output file for generate auto completion script',
// 'envVar' => Console::DEBUG_ENV_KEY,
'default' => 'stdout',
],
'tpl-file' => [
'type' => FlagType::STRING,
'hidden' => true,
'desc' => 'custom tpl file for generate completion script',
// 'default' => 'stdout',
],
];

Expand Down
Loading

0 comments on commit ba69f2e

Please sign in to comment.