Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Add CommandDefinition to make list lazy #39860

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

Conversation

jderusse
Copy link
Member

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? yes
Tickets Fix #33804
License MIT
Doc PR -

This is an alternative to #39851, that use an CommandDescription to expose the command's metadata.

This PR is WIP to get your point of view before moving spending too much time on it.

TODO:

  • add tests
  • trigger exception when command implement the interface and override the methods isEnabled, isHidden, ... meaning
  • add changelog
  • migrate commands (with dependencies) to this interface

@@ -489,9 +489,6 @@ public function add(Command $command)
return null;
}

// Will throw if the command is not correctly initialized.
$command->getDefinition();
Copy link
Member Author

Choose a reason for hiding this comment

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

This break laziness (#39851 should also fix this issue).
I'm not sure why this check is performed here.

Copy link
Member

Choose a reason for hiding this comment

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

Related to #9244 apparently
Apparently, we need to think twice before removing as that might hurt DX.

@OskarStark
Copy link
Contributor

This looks very promising and less "magical" 👍🏻

@ro0NL
Copy link
Contributor

ro0NL commented Jan 16, 2021

DescribableCommandInterface should not be needed IMHO

with >=php8 we can argue attributes are superior either way, and thus we're targetting php7 only

It's really fast to meet the convention from #39851 for the time being (eg. pre-php8 era): $defaultName = 'foo|bar'; and done

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 18, 2021

From a DX perspective, this requires ppl to implement a new static method to gain laziness, which is more code to write.

#39851 provides a descriptive approach instead, that paves the way to configuring the same thing using attributes on PHP 8. Doing so would be a minor implementation change on top of #39851.

What benefit are you expecting from this approach, vs #39851?

As of now, the proposed CommandDescription looks very much like a PHP 8 attribute in disguise.
If we agree on the target that would be to allow using an attribute for the purposed config settings, then I think #39851 is more aligned to this goal.

@jderusse
Copy link
Member Author

What benefit are you expecting from this approach

Cleaner, extensible (ie. allows enabled), self explanatory (|foo|bar is not obviously a hidden command).

If we agree on the target that would be to allow using an attribute for the purposed config settings, then I think #39851 is more aligned to this goal.

I totally agree with this comment (and similar from @ro0NL), if we target php8 attributes, that would make sens to move with #39851 and make the migration smoother

@jderusse jderusse force-pushed the console-command-def branch from 870b131 to 770cf8c Compare January 18, 2021 13:19
@nicolas-grekas
Copy link
Member

Cleaner, extensible (ie. allows enabled), self explanatory (|foo|bar is not obviously a hidden command).

On my side, it looks like more code boilerplate for something that could be just plain descriptive.
About the "self-explanatory" part, it's a very minor thing, and the attribute will improve this anyway.

@jderusse
Copy link
Member Author

Closing in favor of #39851 and a path to php8 attributes

@jderusse jderusse closed this Jan 18, 2021
@jderusse jderusse deleted the console-command-def branch January 25, 2021 09:17
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.

[Console] Distinguish definition of a command from its execution
5 participants