Skip to content

Hide commands from ApplicationDescriptor, but allow invoking #20029

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

Merged
merged 14 commits into from
Oct 5, 2016

Conversation

jwdeitch
Copy link
Contributor

@jwdeitch jwdeitch commented Sep 22, 2016

I would like to hide commands from cluttering the descriptors, but still allow their invocation from code or cron.

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets comma-separated list of tickets fixed by the PR, if any
License MIT
Doc PR reference to the documentation PR, if any

@@ -34,6 +34,7 @@ class Command
private $processTitle;
private $aliases = array();
private $definition;
private $hidden;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be $this->hidden = false;

*
* @return Command The current instance
*/
public function setHidden($hiddenBool)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be $hidden

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed. Thank you sir

@@ -447,6 +448,30 @@ public function getName()
}

/**
* Sets if the command should be hidden from application inspection.
*
* @param bool $hiddenBool To show this command or not
Copy link
Contributor

Choose a reason for hiding this comment

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

Derp.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about To hide the command in application descriptions.

@ogizanagi
Copy link
Contributor

What about other descriptors ?

@ro0NL
Copy link
Contributor

ro0NL commented Sep 25, 2016

@ogizanagi
Copy link
Contributor

@ro0NL, @jwdeitch : Oh right. Sorry. PR title & description may be updated I guess then 😉 .

@jwdeitch jwdeitch changed the title Hide commands from TextDescriptor, but allow invoking Hide commands from ApplicationDescriptor, but allow invoking Sep 25, 2016
@javiereguiluz
Copy link
Member

Could we change the method names to follow the same notation as for services? Instead of setHidden() and isHidden() -> setPublic(true / false) and isPublic() ?

@ro0NL
Copy link
Contributor

ro0NL commented Sep 29, 2016

Maybe if we run a private command it should give you a heads up in verbose mode.. would that be useful?

@jwdeitch
Copy link
Contributor Author

Good idea. Should we merge this first then address that? Or I can throw it into this PR

@ogizanagi
Copy link
Contributor

ogizanagi commented Sep 29, 2016

@jwdeitch : Could you update the test suite (AbstractDescriptorTest) by adding a new private command in DescriptorApplication2 ?

@@ -447,6 +448,30 @@ public function getName()
}

/**
* To hide the command in application descriptions.
*
* @param bool $public To show this command or not
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest something like: Whether the command should be publicly shown or not. and remove the above description (which brings nothing more IMHO).

/**
* Returns if the command is public in application descriptions.
*
* @return bool If the command is public or not
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. I feel this repetition is useless.

*/
public function setPublic($public)
{
$this->public = $public;
Copy link
Member

Choose a reason for hiding this comment

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

should be $this->public = (bool) $public;

*
* @return Command The current instance
*/
public function setPublic($public)
Copy link
Member

Choose a reason for hiding this comment

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

What about setPrivate() without an argument? I don't see a need to switch from private to public.

Copy link
Member

Choose a reason for hiding this comment

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

I suggested changing it to setPublic(false) to mimic Symfony services ... where you must set public: false for private services. If we use opposing techniques to do the same (public: false for services, private: true for commands) we're increasing the learning curve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could meet in the middle at setPublicity as it's not favoring one way or another :)

@fabpot
Copy link
Member

fabpot commented Oct 5, 2016

Thank you @jwdeitch.

@fabpot fabpot merged commit 746dab3 into symfony:master Oct 5, 2016
fabpot added a commit that referenced this pull request Oct 5, 2016
…voking (jwdeitch, Jordan Deitch)

This PR was merged into the 3.2-dev branch.

Discussion
----------

Hide commands from ApplicationDescriptor, but allow invoking

I would like to hide commands from cluttering the descriptors, but still allow their invocation from code or cron.

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any
| License       | MIT
| Doc PR        | reference to the documentation PR, if any

Commits
-------

746dab3 casting setPublic() arg to bool
0a3c290 update docblocks and added test
6d87837 Update ApplicationDescription.php
e969581 update hidden to public
3efa874 Update Command.php
dfc1ac8 Update Command.php
cd77139 Update Command.php
56a8b93 Update Command.php
fb1f30c Update Command.php
1993196 Update Command.php
1add2ad Update Command.php
b73f494 Update ApplicationDescription.php
8d0262f Update Command.php
b423ab4 Add hidden field
@wouterj
Copy link
Member

wouterj commented Oct 20, 2016

I think calling this private will introduce the same confusion that was just solved with the services: I expect I cannot run private commands outside the app, but I still can. It's simply only hidden in the command listing.

Calling this hidden does a better job in describing the feature imo.

@fabpot
Copy link
Member

fabpot commented Oct 21, 2016

I tend to agree with @wouterj. A private command is indeed not really private in the same sense as for the container, it's just hidden from the list of commands and can still be executed like any other commands. @javiereguiluz WDYT?

@javiereguiluz
Copy link
Member

I understand "private" as something hidden, secret, confidential, special. Those are precisely the synonyms of the "private" word. If we talk about commands that cannot be executed outside the app, to me that would be: "banned", "secured", "disabled", "closed", etc.

But if this is confusing to others, then "hidden" is also a very understandable name for this feature.

@stof
Copy link
Member

stof commented Oct 21, 2016

@javiereguiluz the confusion is that it has a different behavior than private in the DI component:

  • in DI, a private service can be injected into other services, but cannot be accessed from the outside of the container
  • in console, a private command can be called like any other command, as long as you know it exists.

@xabbuh
Copy link
Member

xabbuh commented Oct 21, 2016

I agree with @wouterj and @fabpot. I opened #20266 which would rename $public to $hidden.

fabpot added a commit that referenced this pull request Oct 21, 2016
…xabbuh)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Console] rename Command::private to Command::hidden

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20029
| License       | MIT
| Doc PR        |

Commits
-------

f900ef0 rename Command::private to Command::hidden
@fabpot fabpot mentioned this pull request Oct 27, 2016
xabbuh added a commit to symfony/symfony-docs that referenced this pull request Jan 10, 2017
…eguiluz, wouterj)

This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #7052).

Discussion
----------

Added an article about private console commands

This documents symfony/symfony#20029.

Commits
-------

d1cb043 Reflect private to hidden renaming in the file name
01f474f Reflect renaming from private to hidden
9415643 Added an article about private console commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants