yiisoft / yii-console Goto Github PK
View Code? Open in Web Editor NEWYii console components
Home Page: https://www.yiiframework.com/
License: BSD 3-Clause "New" or "Revised" License
Yii console components
Home Page: https://www.yiiframework.com/
License: BSD 3-Clause "New" or "Revised" License
It would be nice if the column headers would be repeated every x
data rows, so you don't loose track which column is which. x
could be linked to the window height.
I think about something like this:
+---------------+----------+-----------+------------+------------+
| name | can read | can write | can update | can delete |
+---------------+----------+-----------+------------+------------+
| john.doe | 1 | 0 | 0 | 0 |
+---------------+----------+-----------+------------+------------+
<about x rows>
+---------------+----------+-----------+------------+------------+
| name | can read | can write | can update | can delete |
+---------------+----------+-----------+------------+------------+
| jane.doe | 1 | 1 | 1 | 1 |
+---------------+----------+-----------+------------+------------+
Configuration path (config-plugin-output-dir) can be set in composer.json
, but is hardcoded in this package.
yii-console/config/console.php
Line 6 in a879c21
Seems as typo and possible meaning 'yii\console\controllers' ? There are no class '\yii\console\controllers' - its a directory
For example ./yii list debug
:
2023-02-10 13:23:45.064400 [error][application] Symfony\Component\Console\Exception\NamespaceNotFoundException: There are no commands defined in the "debug" namespace. in /var/www/app/vendor/symfony/console/Application.php:632 while running console command "list".
Message context:
exception: Symfony\Component\Console\Exception\NamespaceNotFoundException: There are no commands defined in the "debug" namespace. in /var/www/app/vendor/symfony/console/Application.php:632
Stack trace:
#0 /var/www/app/vendor/symfony/console/Descriptor/ApplicationDescription.php(87): Symfony\Component\Console\Application->findNamespace('debug')
#1 /var/www/app/vendor/symfony/console/Descriptor/ApplicationDescription.php(64): Symfony\Component\Console\Descriptor\ApplicationDescription->inspectApplication()
#2 /var/www/app/vendor/symfony/console/Descriptor/TextDescriptor.php(185): Symfony\Component\Console\Descriptor\ApplicationDescription->getCommands()
#3 /var/www/app/vendor/symfony/console/Descriptor/Descriptor.php(43): Symfony\Component\Console\Descriptor\TextDescriptor->describeApplication(Object(Yiisoft\Yii\Console\Application), Array)
#4 /var/www/app/vendor/symfony/console/Helper/DescriptorHelper.php(65): Symfony\Component\Console\Descriptor\Descriptor->describe(Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput), Object(Yiisoft\Yii\Console\Application), Array)
#5 /var/www/app/vendor/symfony/console/Command/ListCommand.php(71): Symfony\Component\Console\Helper\DescriptorHelper->describe(Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput), Object(Yiisoft\Yii\Console\Application), Array)
#6 /var/www/app/vendor/symfony/console/Command/Command.php(312): Symfony\Component\Console\Command\ListCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput))
#7 /var/www/app/vendor/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput))
#8 /var/www/app/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Symfony\Component\Console\Command\ListCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput))
#9 /var/www/app/vendor/symfony/console/Application.php(168): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput))
#10 /var/www/app/vendor/yiisoft/yii-runner-console/src/ConsoleApplicationRunner.php(62): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Yiisoft\Yii\Console\Output\ConsoleBufferedOutput))
#11 /var/www/app/yii(11): Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner->run()
#12 {main}
time: 1676035425.064434
memory: 5885920
category: 'application'
Currently exceptions are print into stdout and aren't logged. Need logging to be configurable.
With :
separator you can run command doctrine:migrations:diff
by d:mi:di
.
This do not work for /
separator. E.g. debug/reset
can't be executed by d/r
mbp:github-dashboard didou$ ./vendor/bin/yii message/config-template --help
Exception 'Error' with message 'Class 'cebe\markdown\Parser' not found'
in /Users/didou/yii3/github-dashboard/vendor/yiisoft/yii-console/src/Markdown.php:24
XDEBUG_TRIGGER=yes php -dxdebug.mode=debug yii serve
in consoleIDE catches the running at needed line
IDE doesn't catch nothing
The problem is located on https://github.com/yiisoft/yii-console/blob/master/src/Command/Serve.php#L97
That command should consider arguments what was passed to original process.
Command:
final class CreateUser extends Command
{
protected static $defaultName = 'user/create';
public function __construct(
private NonExistsClass $userApi,
) {
parent::__construct();
}
}
Exception with message about not instantiable class CreateUser
.
The command "user/create" does not exist.
symfony/console is a great component which many frameworks used. So can we support it , or how can I integrate with it seamless?
Line 13 in a945e7b
It should be $autOloadPath
Create new project. Add console command.
Console command is available.
Console command is not available, until configuration rebuild.
Design for configuration rebuild is now (as of 2020-11-12):
Current console package implementation treats non-set variable YII_ENV as "prod" environment, therefore you have "prod" environment mode right after you have created new project.
Q | A |
---|---|
Version | 3.0 :) |
PHP version | 7.4 |
Operating system | WSL2 |
yii-console/src/Command/Serve.php
Line 138 in a26e643
Create a console command that does echo.
Try to create an automated test for it.
public function actionEcho($str) {
$this->stdOut($str);
}
I should be able to test my code.
I should not be getting output on screen when running my tests.
Due to the fact BaseConsole::stdOut
uses fwrite(\STDOUT
it is hard to properly test the output.
Running console command, if a fatal error happens, I get no error message.
This behavior is annoying and makes it harder to debug problems.
Run console command with fatal bug, for example missing argument in some constructor call.
Eror is displayed in console output
No error messages, just silently exit with error code 1
Q | A |
---|---|
Version | dev-master |
PHP version | 7.4.6 |
Operating system | Windows |
@bscheshirwork commented on Oct 15, 2018, 7:44 AM UTC:
I must typing --interactive=0
or confirm command each time
This keyword is not so short...
I expect the sugar alias options -y
for applying migration's command
non-autocomplited --interactive=0
only
https://github.com/yiisoft/yii2/blob/master/framework/console/Controller.php#L51-L54
Q | A |
---|---|
Yii version | dev |
PHP version | |
Operating system |
This issue was moved by samdark from yiisoft/yii2#16787.
Current configuration:
<?php
return [
'app' => function (\Psr\Container\ContainerInterface $container) {
$app = new \Yiisoft\Yii\Console\Application();
$loader = new \Symfony\Component\Console\CommandLoader\ContainerCommandLoader($container, [
'serve' => 'serve',
]);
$app->setCommandLoader($loader);
return $app;
},
// commands
'serve' => \Yiisoft\Yii\Console\Command\Serve::class,
];
Issues:
serve
in two places.app
config is not merge-able.See also
Line 26 in 57194c4
After #124 aliased commands are properly displayed in the list but still they can not be executed using alias.
The console error message only contains the filename, for example "In GroupManager.php line 131:".
I would like you to add the full path to the file in order to better understand the package of the file.
Q | A |
---|---|
Version | 1.0.? |
PHP version | |
Operating system |
See https://forum.yiiframework.com/t/what-would-be-your-preferred-console-syntax/126506
This event need to move to application tempates.
ConsoleErrorEvent::class => [
[ErrorListener::class, 'onError'],
],
@bscheshirwork commented on Oct 15, 2018, 8:42 AM UTC:
I try to improve alias -y
#16787 but I can't use this construction
Way to create alias within value of option
not implemented
Fr example we can use syntax of 2-element array
['aliasKey' => ['commandOption', 'optionValue']]
we can replace
yii2/framework/console/controllers/MigrateController.php
Lines 160 to 171 in 558cd48
| | public function optionAliases() |
| | { |
| | return array_merge(parent::optionAliases(), [ |
| | 'C' => 'comment', |
| | 'f' => 'fields', |
| | 'p' => 'migrationPath', |
| | 't' => 'migrationTable', |
| | 'F' => 'templateFile', |
| | 'P' => 'useTablePrefix', |
| | 'c' => 'compact', |
| | ]); |
| | } |
yii2/framework/console/Controller.php
Line 106 in 558cd48
| | $params[$optionAliases[$name]] = $value; |
->
public function optionAliases()
{
return array_merge(parent::optionAliases(), [
'C' => 'comment',
'f' => 'fields',
'p' => 'migrationPath',
't' => 'migrationTable',
'F' => 'templateFile',
'P' => 'useTablePrefix',
'c' => 'compact',
'y' => ['-interactive', 0],
]);
}
if (is_array($optionAliases[$name])) {
$params[array_shift($optionAliases[$name])] = array_shift($optionAliases[$name]);
} else {
$params[$optionAliases[$name]] = $value;
}
How about this?
Q | A |
---|---|
Yii version | dev |
PHP version | 7.2.10 |
Operating system | alpine3.8 |
This issue was moved by samdark from yiisoft/yii2#16788.
https://github.com/yii-extension/simple-app/actions/runs/1452155844
[GuzzleHttp\Exception\ConnectException] cURL error 7: Failed to connect to localhost port 8080: Connection refused (see
https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8080/about
Scenario Steps:
#1 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:210
#2 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:158
#3 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:110
#4 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php:47
#5 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php:35
#6 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Middleware.php:37
#7 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php:55
#8 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Middleware.php:63
#9 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\HandlerStack.php:75
#10 D:\a\simple-app\simple-app\vendor\guzzlehttp\guzzle\src\Client.php:331
With the integrated PHP server curl does not fail.
http=>https
Q | A |
---|---|
Version | 1.0.? |
PHP version | |
Operating system |
1, Folder structure
- App
-- Commands
--- HelloController.php
- config
-- common.php
-- console.php
-- params.php
...
- vendor
- composer.json
2, composer.json
{
...
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
},
"config-plugin": {
"params": ["config/params.php"],
"common": ["config/common.php"],
"console": [
"$common",
"config/console.php"
]
}
},
"autoload": {
"psr-4": {
"App\\": "App",
"Lib\\": "Lib"
}
},
}
...
console.php
return [
'app' => [
'controllerNamespace' => 'App\Commands', // (Also trying with App\Commands::class)
],
];
common.php
return [
'app' => [
'basePath' => dirname(__DIR__) . '/App',
],
....
]
When i run
/vendor/bin/yii hello/index
- all correct, it works
When i run
/vendor/bin/yii help
- gotcha error
Error: Invalid path alias: @/App/Commands
Also if i add in my HelloController@actionIndex print app->controllerPath, error also reproduced
public function actionIndex(): int
{
$this->stdout('Hello, Yii3'.PHP_EOL, Console::FG_PURPLE); //It`s normal
// With this line error reproduced
$this->stdout($this->app->controllerPath.PHP_EOL, Console::FG_PURPLE);
return ExitCode::OK;
}
alias should be '@App/Commands'
Error: Invalid path alias: @/App/Commands
Q | A |
---|---|
Yii version | 3.0.? -latest dev-master |
PHP version | 7.3 |
Operating system | ArchLinux |
Actually, my previous PR with some tests for Console helper was inspired exactly by this discovery: one day I looked Yii2 helpers, and suddenly found some... rare syntax in PHP, let's say it that way.
I agree that sometimes it's not so bad to use goto
, but I think it's not such case, and perhaps it's better to replace it with cycles.
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseConsole.php#L799
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseConsole.php#L872
I can make PR, if you share my opinion, after accepting my tests PR.
I must set all of rows in one piece
public function setRows(array $rows)
{
$this->_rows = array_map('array_values', $rows);
return $this;
}
I wish to add row-by-row in my iterator's...
Hello I have an error after last update
PHP Fatal error: Uncaught Yiisoft\Definitions\Exception\NotFoundException: No definition or class found or resolvable for Psr\EventDispatcher\EventDispatcherInterface while building Yiisoft\Yii\Console\SymfonyEventDispatcher -> Psr\EventDispatcher\EventDispatcherInterface. in .../vendor/yiisoft/di/src/Container.php:406
Here is potential place of error:
<?php
declare(strict_types=1);
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Input\InputOption;
use Yiisoft\Definitions\Reference;
use Yiisoft\Yii\Console\Application;
use Yiisoft\Yii\Console\CommandLoader;
use Yiisoft\Yii\Console\SymfonyEventDispatcher;
/** @var array $params */
return [
CommandLoaderInterface::class => [
'class' => CommandLoader::class,
'__construct()' => [
'commandMap' => $params['yiisoft/yii-console']['commands'],
],
],
Application::class => [
'class' => Application::class,
'__construct()' => [
Reference::to(SymfonyEventDispatcher::class),
$params['yiisoft/yii-console']['name'],
$params['yiisoft/yii-console']['version'],
],
'setAutoExit()' => [$params['yiisoft/yii-console']['autoExit']],
'setCommandLoader()' => [Reference::to(CommandLoaderInterface::class)],
'addOptions()' => [
new InputOption(
'config',
null,
InputOption::VALUE_REQUIRED,
'Set alternative configuration name'
),
],
],
];
We need to make a decorator for \Psr\Log\LoggerInterface
that will pass log into \Symfony\Component\Console\Logger\ConsoleLogger
and original logger.
\Psr\Log\LoggerInterface
into command$this->logger->info('This text should be visible in console');
in execute()
methodI have output in console:
This text should be visible in console
Nothing happend
Install a project template, people complaining about too complicated setup.
Example commands
$ yii init
Querying application bases...
[1] yii-base-web
[2] yii-base-api
[3] yii-base-cli
Which one(s) do you want to install?
Copy and paste command from docs.
This is (I think) an error also in Yii2 console.
Help controller actions list is wrong because \yii\console\Application has wrong controllerNamespace that returns wrong list here:
This is the test match list:
yii-console/tests/unit/controllers/HelpControllerTest.php
Lines 66 to 75 in e6252c2
but if we look at controllers folder list :
Currently Symfony console instantiates every command when making a list. That means all the dependencies are instantiated as well. Some of these such as Cycle, are making SQL queries.
Overall, instantiating every command isn't needed since what we need is some meta-data that seems to be OK as static.
TODO:
bin/yii
file is using our own DI container. I guess we shouldn't require it, but we should not use it directly. Any suggestions?
As it was in Yii 2. See discussion https://forum.yiiframework.com/t/cons-and-pros-of-using-symfony-console/126425/14
When I develop different projects, there is a need to run them at the same time. I need to configure for each project its own port for ./yii serve command.
Class \Yiisoft\Yii\Console\Command\Serve is finalized and DEFAULT_PORT is private const. I can't extend it and redeclare DEFAULT_PORT.
I can write script serve
with simple content ./yii serve --port=8081
etc. and ignore it by git. But this solution looks like a crutch
It could be a good idea to introduce abstraction layer before release to be able to do our own implementation if needed later.
See https://forum.yiiframework.com/t/cons-and-pros-of-using-symfony-console/126425/14
Current version
return [
'app' => function () {
...
},
]
and in yii
$container->get('app')->run();
After:
return [
Application::class => function () {
...
},
]
and in yii
$container->get(Application::class)->run();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.