Skip to content

Commit

Permalink
breaking: update plugin exec method params
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 5, 2021
1 parent 5dce6c1 commit 2a9438e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
52 changes: 20 additions & 32 deletions app/Console/Plugin/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

use Inhere\Console\Application;
use Inhere\Console\GlobalOption;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Toolkit\PFlag\Flags;
use Toolkit\PFlag\FlagsParser;
use Toolkit\PFlag\SFlags;
use Toolkit\Stdlib\Helper\DataHelper;
use function array_merge;

Expand All @@ -26,22 +25,22 @@ abstract class AbstractPlugin implements PluginInterface
/**
* @var string
*/
protected $name = '';
protected string $name = '';

/**
* @var string
*/
protected $filepath = '';
protected string $filepath = '';

/**
* @var string
*/
protected $classname = '';
protected string $classname = '';

/**
* @var array
*/
protected $metadata = [];
protected array $metadata = [];

public function init(): void
{
Expand Down Expand Up @@ -93,15 +92,6 @@ protected function createFlags(): FlagsParser
return $this->fs;
}

/**
* @return SFlags
*/
// protected function createSFlags(): SFlags
// {
// $this->fs = new SFlags();
// return $this->fs;
// }

/**
* Metadata for the plugin
*
Expand Down Expand Up @@ -169,7 +159,6 @@ final public function getOptions(): array
public function getSimpleInfo(): array
{
// $meta = $this->metadata();

return [
'name' => $this->name,
// 'desc' => $meta['desc'] ?? '',
Expand All @@ -180,20 +169,6 @@ public function getSimpleInfo(): array
];
}

/**
* @param Application $app
* @param array $args
*/
public function run(Application $app, array $args = []): void
{
$input = $app->getInput();
if (!$this->beforeRun($app, $args)) {
return;
}

$this->exec($app, $input);
}

/**
* @param Application $app
* @param array $args
Expand All @@ -216,9 +191,22 @@ protected function beforeRun(Application $app, array $args): bool

/**
* @param Application $app
* @param Input $input
* @param array $args
*/
public function run(Application $app, array $args = []): void
{
if (!$this->beforeRun($app, $args)) {
return;
}

$this->exec($app, $app->getOutput());
}

/**
* @param Application $app
* @param Output $output
*/
abstract public function exec(Application $app, Input $input): void;
abstract public function exec(Application $app, Output $output): void;

/**
* @return string
Expand Down
6 changes: 3 additions & 3 deletions plugin/AddCommentsToJson5.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);

use Inhere\Console\Application;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Console\Component\Clipboard;
use Inhere\Kite\Console\Component\ContentsAutoReader;
use Inhere\Kite\Console\Plugin\AbstractPlugin;
Expand Down Expand Up @@ -52,9 +52,9 @@ protected function options(): array

/**
* @param Application $app
* @param Input $input
* @param Output $output
*/
public function exec(Application $app, Input $input): void
public function exec(Application $app, Output $output): void
{
$mapFile = $this->fs->getOpt('map-file');
$this->loadMapData($mapFile);
Expand Down
6 changes: 3 additions & 3 deletions plugin/demo-plugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Inhere\Console\Application;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Console\CliApplication;
use Inhere\Kite\Console\Plugin\AbstractPlugin;

Expand All @@ -19,9 +19,9 @@ protected function metadata(): array

/**
* @param Application $app
* @param Input $input
* @param Output $output
*/
public function exec(Application $app, Input $input): void
public function exec(Application $app, Output $output): void
{
vdump(__METHOD__);
}
Expand Down

0 comments on commit 2a9438e

Please sign in to comment.