Skip to content

Commit a8cd18e

Browse files
committed
update Commands compatibility
1 parent 4f78e62 commit a8cd18e

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

src/Commands/AddCommand.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
use DevNet\Cli\Templating\ICodeGenerator;
1616
use DevNet\System\Command\CommandEventArgs;
1717
use DevNet\System\Command\CommandLine;
18+
use DevNet\System\Command\ICommandHandler;
1819
use DevNet\System\Text\StringBuilder;
1920
use DevNet\System\IO\ConsoleColor;
2021
use DevNet\System\IO\Console;
2122

22-
class AddCommand extends CommandLine implements ICodeGenerator
23+
class AddCommand extends CommandLine implements ICommandHandler, ICodeGenerator
2324
{
2425
private CodeGeneratorRegistry $registry;
2526

@@ -45,50 +46,46 @@ public function __construct()
4546

4647
$builder->writeRows($rows);
4748
});
48-
49-
$this->setHandler($this);
5049
}
5150

52-
public function __invoke(object $sender, CommandEventArgs $args): void
51+
public function onExecute(object $sender, CommandEventArgs $args): void
5352
{
54-
$template = $args->getParameter('template');
55-
$name = $args->getParameter('--name');
56-
$output = $args->getParameter('--output');
57-
58-
if (!$template || !$template->getValue()) {
53+
$template = $args->get('template');
54+
if (!$template || !$template->Value) {
5955
Console::$ForegroundColor = ConsoleColor::Red;
6056
Console::writeLine("Template argument is missing!");
6157
Console::resetColor();
6258
return;
6359
}
6460

61+
$name = $args->get('--name');
6562
if (!$name) {
6663
Console::$ForegroundColor = ConsoleColor::Red;
6764
Console::writeLine('The option --name is required!');
6865
Console::resetColor();
6966
return;
7067
}
7168

72-
if (!$name->getValue()) {
69+
if (!$name->Value) {
7370
Console::$ForegroundColor = ConsoleColor::Red;
7471
Console::writeLine('The option --name is missing an argument!');
7572
Console::resetColor();
7673
return;
7774
}
7875

79-
$parameters[$name->getName()] = $name->getValue();
80-
$output = $args->getParameter('--output');
76+
$parameters[$name->Name] = $name->Value;
77+
$output = $args->get('--output');
8178
if ($output) {
82-
if (!$output->getValue()) {
79+
if (!$output->Value) {
8380
Console::$ForegroundColor = ConsoleColor::Red;
8481
Console::writeLine('The option --output is missing an argument!');
8582
Console::resetColor();
8683
return;
8784
}
88-
$parameters[$output->getName()] = $output->getValue();
85+
$parameters[$output->Name] = $output->Value;
8986
}
9087

91-
$templateName = $template->getValue();
88+
$templateName = $template->Value;
9289
$templateName = strtolower($templateName);
9390
$provider = $this->registry->get($templateName);
9491
$generator = $provider->getGenerator();

src/Commands/CommandRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace DevNet\Cli\Commands;
1111

12-
use DevNet\System\Command\ICommand;
12+
use DevNet\System\Command\CommandLine;
1313

1414
class CommandRegistry extends AbstractRegistry
1515
{
@@ -18,7 +18,7 @@ class CommandRegistry extends AbstractRegistry
1818
public static function getSingleton(): static
1919
{
2020
if (!static::$instance) {
21-
static::$instance = new CommandRegistry(ICommand::class);
21+
static::$instance = new CommandRegistry(CommandLine::class);
2222
}
2323

2424
return static::$instance;

src/Commands/NewCommand.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
use DevNet\Cli\Templating\TemplateRegistry;
1414
use DevNet\System\Command\CommandEventArgs;
1515
use DevNet\System\Command\CommandLine;
16+
use DevNet\System\Command\ICommandHandler;
1617
use DevNet\System\IO\ConsoleColor;
1718
use DevNet\System\IO\Console;
1819

19-
class NewCommand extends CommandLine
20+
class NewCommand extends CommandLine implements ICommandHandler
2021
{
2122
private TemplateRegistry $registry;
2223

@@ -26,7 +27,6 @@ public function __construct()
2627

2728
$this->addArgument('template', 'The template project want to create');
2829
$this->addOption('--output', 'Location to place the generated project output', '-o');
29-
$this->setHandler($this);
3030

3131
$this->registry = TemplateRegistry::getSingleton();
3232
$this->registry->set('console', new TemplateProvider('console', 'Create a console application', __DIR__ . '/../../template'));
@@ -44,31 +44,30 @@ public function __construct()
4444
});
4545
}
4646

47-
public function __invoke(object $sender, CommandEventArgs $args): void
47+
public function onExecute(object $sender, CommandEventArgs $args): void
4848
{
49-
$path = null;
50-
$template = $args->getParameter('template');
51-
$output = $args->getParameter('--output');
52-
53-
if (!$template || !$template->getValue()) {
49+
$template = $args->get('template');
50+
if (!$template || !$template->Value) {
5451
Console::$ForegroundColor = ConsoleColor::Red;
5552
Console::writeLine("Template argument is missing!");
5653
Console::resetColor();
5754
return;
5855
}
5956

57+
$path = null;
58+
$output = $args->get('--output');
6059
if ($output) {
61-
if (!$output->getValue()) {
60+
if (!$output->Value) {
6261
Console::$ForegroundColor = ConsoleColor::Red;
6362
Console::writeLine('Directory argument is missing!');
6463
Console::resetColor();
6564
return;
6665
}
67-
$path = $output->getValue();
66+
$path = $output->Value;
6867
}
6968

7069
$destination = implode("/", [getcwd(), $path]);
71-
$templateName = $template->getValue() ?? '';
70+
$templateName = $template->Value ?? '';
7271
$templateName = strtolower($templateName);
7372
$provider = $this->registry->get($templateName);
7473

src/Commands/RunCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function invoke(array $args): void
2929
{
3030
$parser = new Parser();
3131

32-
foreach ($this->getarguments() as $argument) {
32+
foreach ($this->Arguments as $argument) {
3333
$parser->addArgument($argument);
3434
}
3535

36-
foreach ($this->getoptions() as $option) {
36+
foreach ($this->Options as $option) {
3737
$parser->addOption($option);
3838
}
3939

@@ -66,8 +66,8 @@ public function execute(array $parameters, array $arguments): void
6666
$project = $parameters['--project'] ?? null;
6767

6868
if ($project) {
69-
if ($project->getValue()) {
70-
$projectPath = $project->getValue();
69+
if ($project->Value) {
70+
$projectPath = $project->Value;
7171
foreach ($arguments as $key => $arg) {
7272
if ($arg == $project->Name) {
7373
unset($arguments[$key]);

src/Program.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class Program
2323
public static function main(array $args = [])
2424
{
2525
$rootCommand = new CommandLine('devnet', 'DevNet command-line interface');
26-
$rootCommand->addOption('--version', 'Show version information', '-v', null);
26+
$rootCommand->addOption('--version', 'Show version information', '-v');
2727
$rootCommand->setHelp(function ($builder) {
2828
$builder->useDefaults();
2929
$builder->writeLine("Run 'devnet [command] --help' for more information on a command.");
3030
});
3131

3232
$rootCommand->setHandler(function (object $sender, CommandEventArgs $args): void {
33-
$version = $args->getParameter('--version');
33+
$version = $args->get('--version');
3434
if ($version) {
3535
Console::writeline("DevNet CLI: 1.0.0");
3636
return;

0 commit comments

Comments
 (0)