Skip to content

Commit 71d41b1

Browse files
committed
breaking: remove more not used methods and class
1 parent 3e06b07 commit 71d41b1

16 files changed

+92
-345
lines changed
File renamed without changes.

examples/Command/TestCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function commands(): array
4343
* --long,-s option description 1
4444
* --opt option description 2
4545
*
46-
* @param $input
46+
* @param Input $input
4747
* @param Output $output
4848
*/
4949
public function execute(Input $input, Output $output)

src/IO/InputDefinition.php renamed to resource/deprecated/InputDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Time: 下午8:14
77
*/
88

9-
namespace Inhere\Console\IO;
9+
namespace Deprecated;
1010

1111
use Inhere\Console\Util\Helper;
1212
use InvalidArgumentException;

src/AbstractApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ abstract class AbstractApplication implements ApplicationInterface
9292
/** @var array Application config data */
9393
protected $config = [
9494
'name' => 'My Console Application',
95-
'description' => 'This is my console application',
95+
'desc' => 'This is my console application',
9696
'version' => '0.5.1',
9797
'homepage' => '', // can provide you app homepage url
9898
'publishAt' => '2017.03.24',

src/Application.php

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Inhere\Console;
1010

1111
use Closure;
12+
use Inhere\Console\Contract\ApplicationInterface;
1213
use Inhere\Console\Contract\ControllerInterface;
1314
use Inhere\Console\IO\Input;
1415
use Inhere\Console\IO\Output;
@@ -17,6 +18,7 @@
1718
use RuntimeException;
1819
use SplFileInfo;
1920
use Throwable;
21+
use Toolkit\PFlag\SFlags;
2022
use Toolkit\Stdlib\Helper\DataHelper;
2123
use function array_unshift;
2224
use function class_exists;
@@ -40,8 +42,8 @@ class Application extends AbstractApplication
4042
/**
4143
* Class constructor.
4244
*
43-
* @param array $config
44-
* @param Input|null $input
45+
* @param array $config
46+
* @param Input|null $input
4547
* @param Output|null $output
4648
*/
4749
public function __construct(array $config = [], Input $input = null, Output $output = null)
@@ -58,46 +60,40 @@ public function __construct(array $config = [], Input $input = null, Output $out
5860
/**
5961
* {@inheritdoc}
6062
*/
61-
public function controller(string $name, $class = null, $option = null)
63+
public function controller(string $name, $class = null, array $config = []): ApplicationInterface
6264
{
63-
if (is_string($option)) {
64-
$option = [
65-
'description' => $option,
66-
];
67-
}
68-
69-
$this->logf(Console::VERB_CRAZY, 'load group controller: %s', $name);
70-
$this->router->addGroup($name, $class, (array)$option);
65+
$this->logf(Console::VERB_CRAZY, 'register group controller: %s', $name);
66+
$this->router->addGroup($name, $class, $config);
7167

7268
return $this;
7369
}
7470

7571
/**
7672
* Add group/controller
7773
*
78-
* @param string $name
74+
* @param string $name
7975
* @param string|ControllerInterface|null $class The controller class
80-
* @param null|array|string $option
76+
* @param array $config
8177
*
8278
* @return Application|Contract\ApplicationInterface
8379
* @see controller()
8480
*/
85-
public function addGroup(string $name, $class = null, $option = null)
81+
public function addGroup(string $name, $class = null, array $config = []): ApplicationInterface
8682
{
87-
return $this->controller($name, $class, $option);
83+
return $this->controller($name, $class, $config);
8884
}
8985

9086
/**
91-
* @param string $name
87+
* @param string $name
9288
* @param string|ControllerInterface|null $class The controller class
93-
* @param null|array|string $option
89+
* @param array $config
9490
*
9591
* @return Application|Contract\ApplicationInterface
9692
* @see controller()
9793
*/
98-
public function addController(string $name, $class = null, $option = null)
94+
public function addController(string $name, $class = null, array $config = []): ApplicationInterface
9995
{
100-
return $this->controller($name, $class, $option);
96+
return $this->controller($name, $class, $config);
10197
}
10298

10399
/**
@@ -134,16 +130,10 @@ public function addControllers(array $controllers): void
134130
/**
135131
* {@inheritdoc}
136132
*/
137-
public function command(string $name, $handler = null, $option = null)
133+
public function command(string $name, $handler = null, array $config = [])
138134
{
139-
if (is_string($option)) {
140-
$option = [
141-
'description' => $option,
142-
];
143-
}
144-
145-
$this->logf(Console::VERB_CRAZY, 'load application command: %s', $name);
146-
$this->router->addCommand($name, $handler, (array)$option);
135+
$this->logf(Console::VERB_CRAZY, 'register alone command: %s', $name);
136+
$this->router->addCommand($name, $handler, $config);
147137

148138
return $this;
149139
}
@@ -152,15 +142,15 @@ public function command(string $name, $handler = null, $option = null)
152142
* add command
153143
*
154144
* @param string $name
155-
* @param null $handler
156-
* @param null $option
145+
* @param null|mixed $handler
146+
* @param array $config
157147
*
158148
* @return Application
159149
* @see command()
160150
*/
161-
public function addCommand(string $name, $handler = null, $option = null): self
151+
public function addCommand(string $name, $handler = null, array $config = []): self
162152
{
163-
return $this->command($name, $handler, $option);
153+
return $this->command($name, $handler, $config);
164154
}
165155

166156
/**
@@ -260,7 +250,7 @@ protected function getFileFilter(): callable
260250

261251
/**
262252
* @param string $name command name or command ID or command path.
263-
* @param array $args
253+
* @param array $args
264254
*
265255
* @return int|mixed
266256
* @throws Throwable
@@ -322,21 +312,27 @@ public function dispatch(string $name, array $args = [])
322312
/**
323313
* run a independent command
324314
*
325-
* @param string $name Command name
315+
* @param string $name Command name
326316
* @param Closure|string $handler Command class or handler func
327-
* @param array $options
328-
* @param array $args
317+
* @param array $options
318+
* @param array $args
329319
*
330320
* @return mixed
331321
* @throws Throwable
332322
*/
333323
protected function runCommand(string $name, $handler, array $options, array $args)
334324
{
335325
if (is_object($handler) && method_exists($handler, '__invoke')) {
336-
if ($this->input->getSameOpt(['h', 'help'])) {
337-
$desc = $options['description'] ?? 'No command description message';
326+
$fs = SFlags::new();
327+
$fs->addOptsByRules(GlobalOption::getAloneOptions());
328+
$desc = $options['desc'] ?? 'No command description message';
329+
$fs->setDesc($desc);
338330

339-
return $this->output->write($desc);
331+
// save to input object
332+
$this->input->setFs($fs);
333+
334+
if (!$fs->parse($args)) {
335+
return 0; // render help
340336
}
341337

342338
$result = $handler($this->input, $this->output);
@@ -364,18 +360,20 @@ protected function runCommand(string $name, $handler, array $options, array $arg
364360
* Execute an action in a group command(controller)
365361
*
366362
* @param array $info Matched route info
363+
*
367364
* @psalm-param array{action: string} $info Matched route info
365+
*
368366
* @param array $options
369367
* @param array $args
370-
* @param bool $detachedRun
368+
* @param bool $detachedRun
371369
*
372370
* @return mixed
373371
* @throws Throwable
374372
*/
375373
protected function runAction(array $info, array $options, array $args, bool $detachedRun = false)
376374
{
377375
$controller = $this->createController($info);
378-
$controller::setDesc($options['description'] ?? '');
376+
$controller::setDesc($options['desc'] ?? '');
379377

380378
if ($detachedRun) {
381379
$controller->setDetached();

src/Component/Formatter/HelpPanel.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class HelpPanel extends MessageFormatter
3030
/**
3131
* help panel keys
3232
*/
33-
public const DESC = 'description';
33+
public const DESC = 'desc';
3434

3535
public const USAGE = 'usage';
3636

@@ -86,8 +86,8 @@ public static function show(array $config): void
8686
'indentDes' => ' ',
8787
];
8888
$config = array_merge([
89-
'description' => '',
90-
'usage' => '',
89+
'desc' => '',
90+
'usage' => '',
9191

9292
'commands' => [],
9393
'arguments' => [],
@@ -108,9 +108,9 @@ public static function show(array $config): void
108108
}
109109

110110
// description
111-
if ($config['description']) {
112-
$parts[] = "{$option['indentDes']}{$config['description']}\n";
113-
unset($config['description']);
111+
if ($config['desc']) {
112+
$parts[] = "{$option['indentDes']}{$config['desc']}\n";
113+
unset($config['desc']);
114114
}
115115

116116
// now, render usage,commands,arguments,options,examples ...

src/Concern/ApplicationHelpTrait.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use function str_replace;
3636
use function strpos;
3737
use function strtr;
38-
use function vdump;
3938
use const PHP_EOL;
4039
use const PHP_OS;
4140
use const PHP_VERSION;
@@ -123,8 +122,6 @@ public function showHelpInfo(string $command = ''): void
123122

124123
$this->debugf('display application help by input -h, --help');
125124
$this->fire(ConsoleEvent::BEFORE_RENDER_APP_HELP, $this);
126-
$delimiter = $this->delimiter;
127-
$binName = $in->getScriptName();
128125

129126
// built in options
130127
// $globalOptions = self::$globalOptions;
@@ -138,19 +135,18 @@ public function showHelpInfo(string $command = ''): void
138135
$globalOptions['--gen-file'] = 'The output file for generate auto completion script';
139136
}
140137

138+
$binName = $in->getScriptName();
141139
$helpInfo = [
142140
'Usage' => "$binName <info>{command}</info> [--opt -v -h ...] [arg0 arg1 arg2=value2 ...]",
143141
'Options' => FormatUtil::alignOptions($globalOptions),
144142
'Example' => [
145143
'- run a command/subcommand:',
146144
"$binName test run a independent command",
147145
"$binName home index run a subcommand of the group",
148-
sprintf("$binName home%sindex run a subcommand of the group", $delimiter),
149146
'',
150147
'- display help for command:',
151148
"$binName help COMMAND see a command help information",
152149
"$binName home index -h see a subcommand help of the group",
153-
sprintf("$binName home%sindex -h see a subcommand help of the group", $delimiter),
154150
],
155151
'Help' => [
156152
'Generate shell auto completion scripts:',
@@ -244,7 +240,7 @@ public function showCommandList(): void
244240
/** @var AbstractHandler $command */
245241
if (is_subclass_of($command, CommandInterface::class)) {
246242
$desc = $command::getDescription() ?: $placeholder;
247-
} elseif ($msg = $options['description'] ?? '') {
243+
} elseif ($msg = $options['desc'] ?? '') {
248244
$desc = $msg;
249245
} elseif (is_string($command)) {
250246
$desc = 'A handler : ' . $command;
@@ -274,7 +270,7 @@ public function showCommandList(): void
274270
ksort($internalCommands);
275271
Console::startBuffer();
276272

277-
if ($appDesc = $this->getParam('description', '')) {
273+
if ($appDesc = $this->getParam('desc', '')) {
278274
$appVer = $this->getParam('version', '');
279275
Console::writeln(sprintf('%s%s' . PHP_EOL, $appDesc, $appVer ? " (Version: <info>$appVer</info>)" : ''));
280276
}

0 commit comments

Comments
 (0)