Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[2.2][Console] default command #3857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

[2.2][Console] default command #3857

wants to merge 1 commit into from

Conversation

francodacosta
Copy link

For stand alone applications passing a command is mandatory but most of the times not really necessary

So instead of calling my application like this /myapp.php mycommand --my_option I can just write ./myapp.php --my_option

this PR allows for it while allowing to add (and execute) more than one command

You just need to add $app->setDefaultCommandName('command:name'); and if the command is not found the default one will be executed

includes unit tests and does not breack BC

it is the same as symfony/console#2, but I did the pull request on the wrong repository

@@ -56,7 +56,7 @@ class Application
private $autoExit;
private $definition;
private $helperSet;

private $defaultCommandName = null;
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing empty line between the properties and the ocnstructor

@stof
Copy link
Member

stof commented Apr 10, 2012

There is already a place in the Application adding the list command if the input does not have a command name.

@stof
Copy link
Member

stof commented Apr 10, 2012

and the current code is wrong: if the user does a typo when writing a command name, the default command will be called instead of warning the user about the mistake

@francodacosta
Copy link
Author

have you read the PR description? that is actually the intended behavior

the idea is to be able to have applications with only one command without the need to specify the command on the command line

@stof
Copy link
Member

stof commented Apr 10, 2012

@francodacosta using the default command when they are doing a typo ? I don't think it is a good idea. Currently (in master), we suggest possible commands in such case. Thus, arguments passed to this mistyped command would probably not match the argument expected by your default command anyway.

And regarding my comment about the list command, it is about the fact that the code is still there even after your changes, which is either useless (if it is never executed) or broken (if it does weird things)

@ghost
Copy link

ghost commented Apr 11, 2012

@stof - phpDoc definitely works with lowercase typehints, but we do have one strange inconsistency in Symfony2 where we seem to use Boolean over boolean in typehints. They should all be lowercase.

@francodacosta
Copy link
Author

@stof

I'm worried with the fact that I can not make clear the purpose of this change.

It allows the execution of a console application with only one command without having to type the command name.

I have a console application with only one command named foo
it makes no sense to execute ./console foo --option1
this change allows you to execute ./console --option1

I hope now you understand why it is irrelevant to talk about typos in the command name, as there is no command name

The idea that any console application will have lots of commands is not always correct, and this change will serve that use case

I think it is a valid use case, and I've seen more people interested in this on the mailing list.

I don't mind complying with the coding standards and review suggestions, but it might be a waste of time, as you seem more interested in finding reasons not to accept the change than to incorporate it.

Feel free to close the pull request if there is no interest in this change or let me know otherwise

@burn2delete
Copy link

-1 IMHO I dont see this as a valid use case, It would be better coding standards if all console applications used commands even if they only have one function. Just my opinion.

// to execute we execute the default one
if (! is_null($this->getDefaultcommandName())) {
if (! $this->has($this->getCommandName($input))) {
$argv = $_SERVER['argv'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt this wrong? Command could possibly be called from a webserver instead of the command line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is

@stof
Copy link
Member

stof commented Aug 22, 2012

@francodacosta I think this PR will not be mergeable anymore. Github says it is sent from unknown-repository. Have you deleted your fork sending this PR ?

@francodacosta
Copy link
Author

yes

@stof
Copy link
Member

stof commented Aug 23, 2012

@francodacosta so I think we need to close this PR as it cannot be merged.

@stof
Copy link
Member

stof commented Aug 25, 2012

@francodacosta Btw, for the case where your tool only needs one command, a simpler solution is the one used by behat: overwriting the method determining the command name: https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Console/BehatApplication.php#L168-176

stof added a commit to stof/symfony-docs that referenced this pull request Oct 13, 2012
This documents the way to achieve the use case requested in
symfony/symfony#3857
@stof
Copy link
Member

stof commented Oct 13, 2012

Closing this PR: its code is not available anymore, I really don't like the way it is implemented, and there is already a way to build applications with a single command. I opened a PR in the doc to document the way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.