diff --git a/src/AbstractApplication.php b/src/AbstractApplication.php index adf959d..371dd67 100644 --- a/src/AbstractApplication.php +++ b/src/AbstractApplication.php @@ -13,12 +13,12 @@ use Inhere\Console\Component\ErrorHandler; use Inhere\Console\Component\Router; use Inhere\Console\Component\Formatter\Title; -use Inhere\Console\Concern\ApplicationHelpTrait; use Inhere\Console\Concern\InputOutputAwareTrait; use Inhere\Console\Concern\SimpleEventAwareTrait; -use Inhere\Console\Concern\StyledOutputAwareTrait; use Inhere\Console\Contract\ApplicationInterface; use Inhere\Console\Contract\ErrorHandlerInterface; +use Inhere\Console\Decorate\ApplicationHelpTrait; +use Inhere\Console\Decorate\StyledOutputAwareTrait; use Inhere\Console\IO\Input; use Inhere\Console\IO\Output; use Inhere\Console\Util\Helper; diff --git a/src/Application.php b/src/Application.php index 5888d04..eaad033 100644 --- a/src/Application.php +++ b/src/Application.php @@ -20,6 +20,7 @@ use RuntimeException; use Throwable; use Toolkit\FsUtil\Dir; +use Toolkit\PFlag\FlagsParser; use Toolkit\PFlag\SFlags; use Toolkit\Stdlib\Helper\Assert; use Toolkit\Stdlib\Helper\DataHelper; @@ -121,7 +122,7 @@ public function addControllers(array $controllers): void /** * @param string $name - * @param class-string|CommandInterface|null|Closure():void $handler + * @param class-string|CommandInterface|null|Closure(FlagsParser, Output):void $handler * @param array{desc: string, aliases: array, options: array, arguments: array} $config config the command. * * @return Application @@ -138,7 +139,7 @@ public function command(string $name, string|Closure|CommandInterface $handler = * add command * * @param string $name - * @param class-string|CommandInterface|null|Closure():void $handler + * @param class-string|CommandInterface|null|Closure(FlagsParser, Output):void $handler * @param array{desc: string, aliases: array, options: array, arguments: array} $config config the command. * * @return Application diff --git a/src/Concern/AdvancedFormatOutputTrait.php b/src/Concern/AdvancedFormatOutputTrait.php deleted file mode 100644 index 75ce23c..0000000 --- a/src/Concern/AdvancedFormatOutputTrait.php +++ /dev/null @@ -1,19 +0,0 @@ -logf(Console::VERB_DEBUG, 'display all sub-commands list of the group: %s', static::$name); - + $name = self::getName(); + $this->logf(Console::VERB_DEBUG, 'display all sub-commands list of the group: %s', $name); $this->beforeShowCommandList(); - $ref = new ReflectionClass($this); - $sName = self::getName() ?: lcfirst($ref->getShortName()); + $refCls = new ReflectionClass($this); + $sName = $name ?: lcfirst($refCls->getShortName()); if (!($classDes = self::getDesc())) { - $classDes = PhpDoc::description($ref->getDocComment()) ?: 'No description for the command group'; + $classDes = PhpDoc::description($refCls->getDocComment()) ?: 'No description for the command group'; } $commands = []; @@ -109,7 +109,7 @@ public function showCommandList(): void /** * @var $cmd string The command name. */ - foreach ($this->getAllCommandMethods($ref) as $cmd => $m) { + foreach ($this->getAllCommandMethods($refCls) as $cmd => $m) { if (!$cmd) { continue; } diff --git a/src/Concern/FormatOutputAwareTrait.php b/src/Decorate/FormatOutputAwareTrait.php similarity index 98% rename from src/Concern/FormatOutputAwareTrait.php rename to src/Decorate/FormatOutputAwareTrait.php index 08652f5..62ab5ce 100644 --- a/src/Concern/FormatOutputAwareTrait.php +++ b/src/Decorate/FormatOutputAwareTrait.php @@ -7,7 +7,7 @@ * @license https://github.com/inhere/php-console/blob/master/LICENSE */ -namespace Inhere\Console\Concern; +namespace Inhere\Console\Decorate; use Inhere\Console\Component\Formatter\JSONPretty; use Inhere\Console\Console; @@ -21,7 +21,7 @@ /** * Class FormatOutputAwareTrait * - * @package Inhere\Console\Traits + * @package Inhere\Console\Decorate */ trait FormatOutputAwareTrait { diff --git a/src/Concern/RuntimeProfileTrait.php b/src/Decorate/RuntimeProfileTrait.php similarity index 97% rename from src/Concern/RuntimeProfileTrait.php rename to src/Decorate/RuntimeProfileTrait.php index 7cb3609..3dd3524 100644 --- a/src/Concern/RuntimeProfileTrait.php +++ b/src/Decorate/RuntimeProfileTrait.php @@ -7,7 +7,7 @@ * @license https://github.com/inhere/php-console/blob/master/LICENSE */ -namespace Inhere\Console\Concern; +namespace Inhere\Console\Decorate; use InvalidArgumentException; use Toolkit\Stdlib\Helper\PhpHelper; @@ -20,7 +20,7 @@ /** * Trait RuntimeProfileTrait * - * @package Inhere\Library\Concern + * @package Inhere\Console\Decorate */ trait RuntimeProfileTrait { diff --git a/src/Concern/StyledOutputAwareTrait.php b/src/Decorate/StyledOutputAwareTrait.php similarity index 98% rename from src/Concern/StyledOutputAwareTrait.php rename to src/Decorate/StyledOutputAwareTrait.php index d1e6fa7..99b4760 100644 --- a/src/Concern/StyledOutputAwareTrait.php +++ b/src/Decorate/StyledOutputAwareTrait.php @@ -7,7 +7,7 @@ * @license https://github.com/inhere/php-console/blob/master/LICENSE */ -namespace Inhere\Console\Concern; +namespace Inhere\Console\Decorate; use Closure; use Generator; @@ -29,7 +29,7 @@ /** * Trait StyledOutputAwareTrait * - * @package Inhere\Console\Concern + * @package Inhere\Console\Decorate * * @method int info($messages, $quit = false) * @method int note($messages, $quit = false) diff --git a/src/Concern/SubCommandsWareTrait.php b/src/Decorate/SubCommandsWareTrait.php similarity index 98% rename from src/Concern/SubCommandsWareTrait.php rename to src/Decorate/SubCommandsWareTrait.php index da73f18..818bb2a 100644 --- a/src/Concern/SubCommandsWareTrait.php +++ b/src/Decorate/SubCommandsWareTrait.php @@ -7,7 +7,7 @@ * @license https://github.com/inhere/php-console/blob/master/LICENSE */ -namespace Inhere\Console\Concern; +namespace Inhere\Console\Decorate; use Closure; use Inhere\Console\Command; @@ -30,7 +30,7 @@ /** * Trait SubCommandsWareTrait * - * @package Inhere\Console\Concern + * @package Inhere\Console\Decorate */ trait SubCommandsWareTrait { diff --git a/src/Concern/UserInteractAwareTrait.php b/src/Decorate/UserInteractAwareTrait.php similarity index 98% rename from src/Concern/UserInteractAwareTrait.php rename to src/Decorate/UserInteractAwareTrait.php index 3f8782c..c1c438a 100644 --- a/src/Concern/UserInteractAwareTrait.php +++ b/src/Decorate/UserInteractAwareTrait.php @@ -7,7 +7,7 @@ * @license https://github.com/inhere/php-console/blob/master/LICENSE */ -namespace Inhere\Console\Concern; +namespace Inhere\Console\Decorate; use Closure; use Inhere\Console\Util\Interact; @@ -17,7 +17,7 @@ /** * Class UserInteractAwareTrait * - * @package Inhere\Console\Concern + * @package Inhere\Console\Decorate * @see Interact * * @method string readRow($message = null, $nl = false) diff --git a/src/Handler/AbstractHandler.php b/src/Handler/AbstractHandler.php index ab5776b..45cc345 100644 --- a/src/Handler/AbstractHandler.php +++ b/src/Handler/AbstractHandler.php @@ -12,14 +12,14 @@ use Inhere\Console\Annotate\DocblockRules; use Inhere\Console\Component\ErrorHandler; use Inhere\Console\Concern\AttachApplicationTrait; -use Inhere\Console\Concern\CommandHelpTrait; use Inhere\Console\Concern\InputOutputAwareTrait; -use Inhere\Console\Concern\SubCommandsWareTrait; -use Inhere\Console\Concern\UserInteractAwareTrait; +use Inhere\Console\Decorate\UserInteractAwareTrait; use Inhere\Console\Console; use Inhere\Console\ConsoleEvent; use Inhere\Console\Contract\CommandHandlerInterface; use Inhere\Console\Contract\CommandInterface; +use Inhere\Console\Decorate\CommandHelpTrait; +use Inhere\Console\Decorate\SubCommandsWareTrait; use Inhere\Console\IO\Input; use Inhere\Console\IO\Output; use Inhere\Console\Util\Helper; @@ -54,22 +54,23 @@ abstract class AbstractHandler implements CommandHandlerInterface use SubCommandsWareTrait; /** - * group/command name e.g 'test' 'test:one' + * The group/command name e.g 'test' 'test:one' * * @var string */ protected static string $name = ''; /** - * command/controller description message - * please use the property setting current controller/command description + * The command/controller description message. + * + * TIP: please use the property setting current controller/command description * * @var string */ protected static string $desc = ''; /** - * command/controller description message + * The command/controller description message * * @var string * @deprecated please use {@see $desc} @@ -327,7 +328,7 @@ public function run(array $args): mixed * * @param array $args * - * @return int|mixed + * @return mixed */ protected function doRun(array $args): mixed { diff --git a/src/IO/Output.php b/src/IO/Output.php index 87b5bff..a06eca3 100644 --- a/src/IO/Output.php +++ b/src/IO/Output.php @@ -9,7 +9,7 @@ namespace Inhere\Console\IO; -use Inhere\Console\Concern\FormatOutputAwareTrait; +use Inhere\Console\Decorate\FormatOutputAwareTrait; use Inhere\Console\Console; use Inhere\Console\IO\Output\StreamOutput; use Toolkit\Cli\Cli; diff --git a/src/Util/Helper.php b/src/Util/Helper.php index 216a3f9..4d0a758 100644 --- a/src/Util/Helper.php +++ b/src/Util/Helper.php @@ -10,7 +10,7 @@ namespace Inhere\Console\Util; use FilesystemIterator; -use Inhere\Console\Concern\RuntimeProfileTrait; +use Inhere\Console\Decorate\RuntimeProfileTrait; use Inhere\Console\ConsoleConst; use InvalidArgumentException; use RecursiveCallbackFilterIterator; @@ -69,16 +69,6 @@ public static function hasMode(int $haystack, int $value): bool return ($haystack & $value) > 0; } - /** - * @param string $path - * - * @return bool - */ - public static function isAbsPath(string $path): bool - { - return str_starts_with($path, '/') || 1 === preg_match('#^[a-z]:[\/|\\\]{1}.+#i', $path); - } - /** * @param string $name */ diff --git a/src/Util/PhpDevServe.php b/src/Util/PhpDevServe.php index 5411597..da8890d 100644 --- a/src/Util/PhpDevServe.php +++ b/src/Util/PhpDevServe.php @@ -13,6 +13,7 @@ use Exception; use RuntimeException; use Toolkit\Cli\Cli; +use Toolkit\FsUtil\Path; use Toolkit\Stdlib\Json; use Toolkit\Sys\Sys; use function explode; @@ -189,7 +190,7 @@ protected function printDefaultMessage(): void $docRoot = $workDir; if ($this->docRoot) { $docRoot = $this->docRoot; - $docRoot = Helper::isAbsPath($docRoot) ? $docRoot : $workDir . '/' . $docRoot; + $docRoot = Path::isAbsPath($docRoot) ? $docRoot : $workDir . '/' . $docRoot; } Cli::writeln([ diff --git a/test/TestCommand.php b/test/TestCommand.php index f8277ab..f854461 100644 --- a/test/TestCommand.php +++ b/test/TestCommand.php @@ -22,7 +22,7 @@ class TestCommand extends Command { protected static string $name = 'test1'; - protected static string $description = 'command description message'; + protected static string $desc = 'command description message'; /** * do execute command diff --git a/test/TestController.php b/test/TestController.php index 5025568..01a2430 100644 --- a/test/TestController.php +++ b/test/TestController.php @@ -20,7 +20,7 @@ class TestController extends Controller { protected static string $name = 'test'; - protected static string $description = 'controller description message'; + protected static string $desc = 'controller description message'; /** * this is an demo command in test