Giter VIP home page Giter VIP logo

console's People

Contributors

andrewsville avatar davidkrupicka avatar enumag avatar fabik avatar foglcz avatar foxycode avatar fprochazka avatar galvani avatar grongor avatar h4kuna avatar jakub-fajkus avatar juniwalk avatar kratkyzobak avatar kuceramartin avatar martinmystikjonas avatar matej21 avatar mikulas avatar milanpala avatar mishak87 avatar mrtnzlml avatar pechondra avatar pepakriz avatar slepic avatar spamercz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

console's Issues

Version for Nette 2.1

Can you please publish new version for Nette 2.1? Currently there is support for Nette 2.1 only in master. Thanks in advance!

%wwwDir%

Ahoj,
používám rozšíření webloader, kde načítám soubory pomocí %wwwDir% (/www/mujprojekt)
,ale když chci spustit: php bin/console command
tak mi to padne na chybě, že neumí najít soubory, protože v tomhle kontextu je %wwwDir% - /www/mujprojekt/bin

Handle (don't log) exception on unknown command/argument

> bin o:su --force
There are no commands defined in the "o:su" namespace.

  Did you mean one of these?
      orm:generate
      orm:clear-cache
      orm
      orm:schema-tool



  (Tracy output was stored in exception-2014-05-13-07-58-20-2d1c81e8f09cc64beeb6389404440c66.html)

Should show only the message and return code for unknown command. IMO Tracy is not supposed to log error produced by use mistake.

Drop dependency on Nette\Application

I don't understand why does console need to depend on Nette\Application so I'd like to propose to relax this dependency.

To make it a bit clearer. I'd like to do this:

$dic = require __DIR__ . '/../app/bootstrap.php';
$app = $dic->getByType(Kdyby\Console\Application::class);
$app->run();

Please configure the Doctrine extensions using the section 'doctrine:'

Ahoj,

chcel by som sa opytat, popr. mat jeden dotaz.
Webova aplikacia mi funguje skvele, bez najmensich problemov, pracujem s DB, insertujem, updatujem, selectujem. Ale akonahle idem pustit hocijaky command

php www/index.php

tak mi vybehne tato chyba

Please configure the Doctrine extensions using the section 'doctrine:'

Mam ju ale registrovanu:

extensions:
  doctrine: Kdyby\Doctrine\DI\OrmExtension


doctrine:
  metadata:
    App: %appDir%/model/entities # temporary /entites cause Nette default models

Je mozne, ze to ma cache ?

Dvě aplikace s jedním vendor

Ahoj,
mám use case se kterým se chci podělit.

Máme aplikaci kde je stará část a nová. Stará jede a nová se vyvíjí obě mají společný vendor. Na nové verzi využíváme kdyby\console a na staré ji nechceme takže není ani definovaný extension v neonu. Jenže nette 2.3 jak si hledá presentery, aby je uložil do Containeru a připravil je jako služby, tak stará aplikace přestala chodit, protože nette našlo KdybyModule\CliPresenter a to má závislosti na Kdyby\Application. Dohledal jsem že to jde vypnout

application:
    scanComposer: false

V tuto chvíli je to takto dostačující, ale připravili jsme se o možnost načítat presentery přes composer, což zatím nepoužíváme ani na jedné verzi.

Error handling - wrong router

Hi, I found this potentialy problem.

If I have router e.g.

<?php
class RouterFactory
{
    public function createRouter()
    {
        $privateRouter = new RouteList('Private');

        $privateRouter[] = new Route('<module>/<presenter>[/<action>][/<id>]',
                array(
                    'module' => 'Dashboard',
                    'presenter' => 'Dashboard',
                    'action' => 'default',
                ));
        return $privateRouter;
    }
}

Console return error like
[Nette\Application\BadRequestException]
Cannot load presenter 'Private:Kdyby:Cli', class 'App\PrivateModule\KdybyModule\Presenter\CliPresenter' was not found in '/home/vagrant/sources/personal/baria/baria _crm/app/core/PrivateModule/KdybyModule/presenters/CliPresenter.php'.

Solution:

Creating RouteList without module specification and insert Concrete module RouteList to them.

<?php
class RouterFactory
{
    public function createRouter()
    {
        $router = new RouteList();
        $privateRouter = new RouteList('Private');

        $privateRouter[] = new Route('<module>/<presenter>[/<action>][/<id>]',
                array(
                    'module' => 'Dashboard',
                    'presenter' => 'Dashboard',
                    'action' => 'default',
                ));

        $router[] = $privateRouter;
        return $privateRouter;
    }
}

Container is not available in Command::configure

I would like to have the parameters section available already in configure so I can provide sensible defaults based on the configuration (from config.neon).

Unfortunatelly, the commands are configured from their constructor and so the helper set is not yet injected => we can't call the container helper (that only happens in Application::add but that is too late as it accepts the command as already constructed parameter).

The way I got around this was to extend the command and pass it the container via constructor. It's not pretty but it works.

Do you guys have some better ideas about how to solve this chicken&egg problem, best in some automagic way so the user doesn't have to deal with each command manually.

Here's the sample code

console:
    commands:
        - App\Console\AppCommand(@container)
class AppCommand extends Command
{
    private $container;

    // TODO: prasarna, ale by default $container este nie je pristupny v configure
    public function __construct(\Nette\DI\Container $container) {
        $this->container = $container;
        parent::__construct(); // calls $this->configure()
    }

    protected function configure()
    {
        $parameters = $this->container->getParameters()['config'];
        $this->addOption(
            'destination-db-host', 'e', InputOption::VALUE_REQUIRED,
            "destination db host",
            $parameters['defaultDestinationDbHost']
        );
        //
    }
}

Tester - running command line test with fpm-cgi disables extension

I want to test command, but got some troubles.
It's probably php.ini related, but I'm new to Tester, so not sure:

PHP_SAPI is various:

  1. command line (e.g. php www/index.php list) - cli
  2. tester in command line - cgi-fcgi

Case 2) disables extension here

What to place to my test file [https://github.com/Kdyby/Console/blob/master/tests/php.ini-unix] to make it work?

Or somewhat else?

Thank you

Basic Nette commands

  • clear cache
  • maintenance mode switch (how would it switch back?)
  • archive-logs (would remove email-sent and create timestamp directory and move all current log files there)

What else do you have in mind?

Shouldn't we run the Nette\Application\Application onShutdown event?

onStartup is called because so far the control wasn't handled over to Kdyby\Console\Application, but the original onShutdown is ignored (you call onError however).

If this is undesirable, maybe a way to attach console-only shutdown event would be helpful.

My usecase right now is: I use symfony/process to start some background processes, but when the main process dies it kills the children (standard unix behaviour). So on the shutdown hook I want to wait for the child processes to finish, then really terminate. I want to wait up in both web request and console request, so for me a common handler is fine (plus you can always test there if you run in the cli)

Bad absolute path when not in a domain root

When I set up in config:

console:
    url: http://domain.tld/path

and then use Nette\Application\LinkGenerator or Nextras\Application\LinkFactory in a command:

$this->linkFactory->link('Presenter:method', ['code' => $code]);

it returns me http://domain.tld/ABCDEF instead of http://domain.tld/path/ABCDEF.

Kdyby\Console requires app router to be a RouteList instance

Recently we've run into the problem that Kdyby\Console is not happy with a router being an IRouter but insist it has to be a RouteList.

Unfortunatelly, in our case that is not technically possible. And even if it was (we can subclass the RouteList, right), the whole reason it has to be (to be able to prepend the CliRouter to the router list) wouldn't work anyway.

It is obvious that the whole reason for the CliRouter is that one is able to fire up the Nette app from the console just like from the browser and it redirects its requests to the Kdyby\Console\Application via the CliPresenter.

I have two possible solutions.

  1. Make the route juggling optional. Just like @JanTvrdik here (#30) we run the Kdyby\Console\Application directly when in CLI. So we don't need to modify the router in the first place.
  2. Make it more robust. Don't require the router to be a RouteList.
    • If it is, do your route juggling.
    • If it isn't, replace it with a RouteList instance, where the first route is your CliRouter and the second is the original IRoute implementation.

The second solution looks way better to me (although there is probably a cave eat - if other DI extensions modify the router too, the ConsoleExtension would have to be the last because this modification would (could?) not be done at run time but at DIC compile time. Anyway, I can prepare a pull request if you decide to go that way.

Command cannot depend on other command

So I have interesting use-case. I have a command, which I want to execute from other command -- because one is maintenance and one is a one-time migration, which is quite extensive (essentially, we're upgrading systems.)

Soooo, I've did this:

console:
    commands:
        - App\Commands\Maintenance\Focus\Paths(%focusPaths%, @focusDibi.connection)
        - App\Commands\MigrationScripts\Y2016Q1\CleanupFocus(%focusPaths%, @focusDibi.connection)

Constructor looks like this:

namespace App\Commands\MigrationScripts\Y2016Q1;

use App\Commands\Maintenance\Focus\Paths;
use Dibi\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CleanupFocus extends Command
{
    /** @var Paths */
    private $pathsCommand;

    public function __construct(array $paths, Connection $focusDibi, Paths $pathsCommand)
    {
        parent::__construct('migrate:y2016q1:focus');
        $this->setDescription('Migrations for FOCUS database, 2016/Q1, the infrastructure overhaul');
        $this->pathsCommand = $pathsCommand;
        // ...
    }

    public function execute(InputInterface $input, OutputInterface $output)
    {
        // ...

        // set options & run the maintenance
        $input->setOption('all', true);
        $input->setOption('force', true);
        $this->pathsCommand->execute($input, $output);

        // ...
    }
}

BUT the DI builder throws a following exception:

[2016-02-08 19-50-14] Nette\DI\ServiceCreationException:
Service 'console.command.0':
Service of type App\Commands\Maintenance\Focus\Paths needed by App\Commands\MigrationScripts\Y2016Q1\CleanupFocus::__construct() not found. 
Did you register it in configuration file? 

Stack trace:
#0 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\Compiler.php(213): Nette\DI\ContainerBuilder->generateClasses(NULL, NULL)
#1 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\Compiler.php(139): Nette\DI\Compiler->generateCode(NULL, NULL)
#2 C:\Users\pptacek\www\projectname,ha!\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(264): Nette\DI\Compiler->compile()
#3 [internal function]: Nette\Configurator->generateContainer(Object(Nette\DI\Compiler))
#4 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\ContainerLoader.php(111): call_user_func_array(Array, Array)
#5 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\ContainerLoader.php(76): Nette\DI\ContainerLoader->generate('Container_168f2...', Array)
#6 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\ContainerLoader.php(41): Nette\DI\ContainerLoader->loadFile('Container_168f2...', Array)
#7 C:\Users\pptacek\www\projectname,ha!\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(218): Nette\DI\ContainerLoader->load(Array, Array)
#8 C:\Users\pptacek\www\projectname,ha!\app\bootstrap.php(23): Nette\Configurator->createContainer()
#9 C:\Users\pptacek\www\projectname,ha!\www\index.php(6): require('C:\\Users\\pptace...')
#10 {main}
(stored in C:\Users\pptacek\www\projectname,ha!\app\..\log\exception--2016-02-08--19-50--1b383ca34c.html)�

If you'd point me to the proper point where I can fix this one, I'd apprecieate it. Cannot continue on it today, but will jump on it first thing tomorrow morning (basically - I need it working :)) )

Creating an issue, since in services section of Nette DI, you can reference other services from constructors -- so this is solvable, somehow.

I know, hotfix might be using @inject - didn't test.

ConsoleExtension: application crash

In file Kdyby\Console\DI\ConsoleExtension on line 75 there is an addSetup method which replaces router service with new Nette\Application\Routers\RouteList to ensure that CliRouter goes first. This is just fine until you want to use Kdyby\Events on the router. If I add any event to the router then application crashes because of this service replacement.

Here is code generated by compiler:

/**
 * @return Router
 */
public function createServiceRouter()
{
    $service = new Router($this->getService('localization'));
    $service->injectRouters($this->getService('redisRouter'));
    $service = Kdyby\Console\CliRouter::prependTo($service, $this);
    $service->onRequestMatched = $this->getService('events.manager')->createEvent(array('Router', 'onRequestMatched'), $service->onRequestMatched);
    $service->onUrlConstructed = $this->getService('events.manager')->createEvent(array('Router', 'onUrlConstructed'), $service->onUrlConstructed);
    return $service;
}

You see? There are no onRequestMatched or onUrlConstructed properties in the class Nette\Application\Routers\RouteList so the application throws error.

Command groups

Something like

$ php www/index.php kdyby:command-groups:export

will create runners in temp/ that will be added into projects composer.json into extra: bins and composer will then link them to vendor/bin.

The runners must get the commands by searching of tags on Container, so the command doesn't have to be run every time you add Command.

Every command will be in "default" group by default, that will be available from www/index.php. If you add it to another group, it will no longer be in "default" group, becase the "default" group will be added only when command has no groups. That means you could still add it to "default" group.

Then you could run them from there afterwards.

$ vendor/bin/app-crons emails:send 
$ vendor/bin/doctrine orm:validate-schema
$ vendor/bin/utils user:create
$ vendor/bin/dangerous-commands-that-could-damage-database recalculate:credits

You should also be able to create your own runner and add some custom logic. Therefore there has to be a factory that will create the Console\Application object with commands from given group and you could then wrap it or whatever. This one needs a bit more thinking :)

Inspired by @VasekPurchart


Motivation: on the general runner you don't need to see crons and every single tool, you only need few basic commands like orm:validate etc. When you get over 20+ commands it get's confusing. This separation should make the usage and orientation easier.

console.url lacks flexibility

On localhost, I use special URL for my app in following format:

www.foo.com.local

But your regexp doesn't allow that. Could the check be less restrictive or removed at all?

Compatibility with Symfony/Console 2.6

Kdyby/Console 2.4.0 and 2.3.2 is not compatible with Symfony/Console 2.6.x

Service 'console.helperSet': Unable to pass arguments, class Symfony\Component\Console\Helper\ProgressHelper has no constructor.
Service 'console.helperSet': Unable to pass arguments, class Symfony\Component\Console\Helper\DialogHelper has no constructor.

Deprecated exceptions

Hello.

First of all, let me say thank you for this amazing component! It used to work without any problems, but now after I do clean composer install with "kdyby/console": "2.3.*@dev" in composer.json I get deprecated exceptions like this one when I try to run console:

exception 'ErrorException' with message '"
Symfony\Component\Console\Helper\DialogHelper" is deprecated since version 2.5 and will be removed in 3.0.
Use "Symfony\Component\Console\Helper\QuestionHelper" instead.'
in C:\dev\www\tome\vendor\symfony\console\Symfony\Component\Console\Helper\DialogHelper.php:34

DI injection for commands?

Nebyl by tady nějaký injecting? Toto DI není úplně ok ne? od doby co global context je fuj?

class SendNewslettersCommand extends Command
{
    protected function configure()
    {
        $this->setName('app:newsletter')
            ->setDescription('Sends the newsletter');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $newsletterSender = $this->getHelper('container')->getByType('Models\NewsletterSender');

Argument 1 passed to Symfony\Component\Console\Application::renderException() must be an instance of Exception, instance of TypeError given

Is this issue of Symfony/Console or Kdyby/Console?

Since Symfony\Component\Console\Application::renderException(\Exception $e, OutputInterface $output) is excepting type of \Exception type errors should not be sent to it.

Problem is in Kdyby\Console\Application::handleException() where renderException() is called.

Any ideas how to fix this?

Anyways type error causing the exception is:
Argument 1 passed to Zenify\DoctrineMigrations\EventSubscriber\ChangeCodingStandardEventSubscriber::getMigrationFileByVersion() must be of the type st ...

kdyby/console failed to update, invalid composer.json data

The kdyby/console package of which you are a maintainer has
failed to update due to invalid data contained in your composer.json.
Please address this as soon as possible since the package stopped updating.

It is recommended that you use composer validate to check for errors when you
change your composer.json.

Below is the full update log which should highlight errors as
"Skipped branch ...":

[Composer\Repository\InvalidRepositoryException]: Some branches contained invalid data and were discarded, it is advised to review the log and fix any issues present in branches

Reading composer.json of kdyby/console (v2.7.1)
Importing tag v2.7.1 (2.7.1.0)
Reading composer.json of kdyby/console (v2.7.0)
Importing tag v2.7.0 (2.7.0.0)
Reading composer.json of kdyby/console (v2.6.3)
Importing tag v2.6.3 (2.6.3.0)
Reading composer.json of kdyby/console (v2.6.1)
Importing tag v2.6.1 (2.6.1.0)
Reading composer.json of kdyby/console (v2.6.0)
Importing tag v2.6.0 (2.6.0.0)
Reading composer.json of kdyby/console (v2.5.0)
Importing tag v2.5.0 (2.5.0.0)
Reading composer.json of kdyby/console (v2.4.0)
Importing tag v2.4.0 (2.4.0.0)
Reading composer.json of kdyby/console (v2.3.2)
Importing tag v2.3.2 (2.3.2.0)
Reading composer.json of kdyby/console (v2.3.1)
Importing tag v2.3.1 (2.3.1.0)
Reading composer.json of kdyby/console (v2.3.0)
Importing tag v2.3.0 (2.3.0.0)
Reading composer.json of kdyby/console (v2.2.3)
Importing tag v2.2.3 (2.2.3.0)
Reading composer.json of kdyby/console (v2.2.2)
Importing tag v2.2.2 (2.2.2.0)
Reading composer.json of kdyby/console (v2.2.1)
Importing tag v2.2.1 (2.2.1.0)
Reading composer.json of kdyby/console (v2.2.0)
Importing tag v2.2.0 (2.2.0.0)
Reading composer.json of kdyby/console (v2.1)
Importing tag v2.1 (2.1.0.0)
Reading composer.json of kdyby/console (v2.0.1)
Importing tag v2.0.1 (2.0.1.0)
Reading composer.json of kdyby/console (v2.0)
Importing tag v2.0 (2.0.0.0)
Reading composer.json of kdyby/console (v1.1.6)
Importing tag v1.1.6 (1.1.6.0)
Reading composer.json of kdyby/console (v1.1.5)
Importing tag v1.1.5 (1.1.5.0)
Reading composer.json of kdyby/console (v1.1.4)
Importing tag v1.1.4 (1.1.4.0)
Reading composer.json of kdyby/console (v1.1.3)
Importing tag v1.1.3 (1.1.3.0)
Reading composer.json of kdyby/console (v1.1.2)
Importing tag v1.1.2 (1.1.2.0)
Reading composer.json of kdyby/console (v1.1.1)
Importing tag v1.1.1 (1.1.1.0)
Reading composer.json of kdyby/console (v1.1.0)
Importing tag v1.1.0 (1.1.0.0)
Reading composer.json of kdyby/console (v1.0.1)
Importing tag v1.0.1 (1.0.1.0)
Reading composer.json of kdyby/console (v1.0.0)
Importing tag v1.0.0 (1.0.0.0)
Reading composer.json of kdyby/console (master)
Importing branch master (dev-master)
Skipped branch master, Invalid package information:
License "GPL-2.0" is a deprecated SPDX license identifier, use "GPL-2.0-only" or "GPL-2.0-or-later" instead
License "GPL-3.0" is a deprecated SPDX license identifier, use "GPL-3.0-only" or "GPL-3.0-or-later" instead

Reading composer.json of kdyby/console (nette-2.0)
Importing branch nette-2.0 (dev-nette-2.0)
Reading composer.json of kdyby/console (nette-2.1)
Importing branch nette-2.1 (dev-nette-2.1)
Reading composer.json of kdyby/console (nette-2.2)
Importing branch nette-2.2 (dev-nette-2.2)
Reading composer.json of kdyby/console (nette-2.3)
Importing branch nette-2.3 (dev-nette-2.3)

Errors during console presenter/application startup get silenced

Hi,

the DI extension exits the application on error, silencing default error handler as the console application formats the errors better. (

if (PHP_SAPI === ConsoleApplication::CLI_SAPI) {
,
$this->handleException($e, $output);
).

BUT if creation of console presenter / application fails (for example, when I misconfigured some service that gets used in injectPrimary of Nette\Application\UI\Presenter), the Nette application simply quits, because the console application does not run at all and there is no output at all.

I guess the solution would be to setup the Nette application onError handler in the CliPresenter, directly before it calls $this->console->run, would that be OK? Am I missing the point of setting the onError so early?

I would gladly prepare the PR if this or other solution is approved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.