JoeCianflone
JoeCianflone

Reputation: 682

a "blank" command for symfony2 console

I've created a little command line tool to help me launch sites. It uses Symfony2 console to help create the commands and add some structure. What I'm trying to figure out is if there is a way, I can crate a "blank" or a default command so if you don't put in a command it just defaults to this. An example might help explain:

A "normal" console command would look like this:

php launch site foo

I want to make this do the exact same thing as above:

php launch foo

The only thing I can think of is to sort-of short circuit the application->run process and check if "foo" is in my own command list, if it's not then force the console to run site foo. The crappy thing about that is if you just typo'ed a different command, the system would just try and run as a site and instead of an error message you'd get an error saying it can't launch that site (which is an error, but the wrong error and not a helpful one to a user).

Maybe I missed something in the console docs, but is there a way to do what I'm trying here?

Upvotes: 0

Views: 138

Answers (1)

JoeCianflone
JoeCianflone

Reputation: 682

So what I ended up doing was just attempt my own match, if I can find the command, then I run the application as normal, if not, I try to launch the site:

    if (!array_key_exists($argv[1], $list))
    {
        $cmd = $this->application->find('launch');
        $args = array(
            'command' => 'launch',
            'alias' => $argv[1]
        );

        $input = new ArrayInput($args);
        $output = new ConsoleOutput();
        $cmd->run($input, $output);
    }
    else
    {
        $this->application->run();
    }

It works fine, it just feels a little meh, I'm open to other suggestions if anyone has them.

Upvotes: 0

Related Questions