Skip to content

[Console] Show available commands in namespace when running namespace as command #47750

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 1 commit into from
Oct 9, 2022

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Sep 30, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR n/a

Another little UX improvement found in the Docker CLI: When running the namespace as a command (e.g. bin/console make), instead of showing an error "this command does not exist", show the list of sub-commands in that namespace.

I've kept the exit code and dispatching of the error event in place, to avoid any BC breaks on this matter.

Before

$ bin/console debug


  Command "debug" is not defined.

  Did you mean one of these?
      debug:autowiring
      debug:config
      debug:container
      debug:dotenv
      debug:event-dispatcher
      debug:router

After

$ bin/console debug
Symfony 6.2.0-DEV (env: dev, debug: true) #StandWithUkraine https://sf.to/ukraine

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -e, --env=ENV         The Environment name. [default: "dev"]
      --no-debug        Switch off debug mode.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands for the "debug" namespace:
  debug:autowiring        List classes/interfaces you can use for autowiring
  debug:config            Dump the current configuration for an extension
  debug:container         Display current services for an application
  debug:dotenv            Lists all dotenv files with variables and values
  debug:event-dispatcher  Display configured listeners for an application
  debug:router            Display current routes for an application

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

@Chris53897
Copy link
Contributor

It would be great improvement in my eyes, if the available commands can have a shortcut with a number. If you enter the number the command will be executed.
But i am not sure if this in the scope of this PR and how much work this would be.

Available commands for the "debug" namespace: (1) debug:autowiring List classes/interfaces you can use for autowiring (2) debug:config Dump the current configuration for an extension (3) debug:container Display current services for an application (4) debug:dotenv Lists all dotenv files with variables and values (5) debug:event-dispatcher Display configured listeners for an application (6) debug:router Display current routes for an application

@wouterj wouterj force-pushed the console-list-namespace branch from a8c7a24 to 912ecd8 Compare October 9, 2022 22:10
@wouterj
Copy link
Member Author

wouterj commented Oct 9, 2022

Hi @Chris53897! It may be a cool idea to explore further, but it is a bit out of scope for the current implementation. Currently, this PR reuses the list command (bin/console demo effectively is "aliased" to bin/console list demo), so we cannot customize anything in the output at the moment. Let's keep version 1 of this feature simple, and iterate on it in new PRs from the community :)

@chalasr
Copy link
Member

chalasr commented Oct 9, 2022

Thank you @wouterj.

@chalasr chalasr merged commit f91c965 into symfony:6.2 Oct 9, 2022
@wouterj wouterj deleted the console-list-namespace branch October 10, 2022 06:58
@fabpot fabpot mentioned this pull request Oct 24, 2022
nicolas-grekas added a commit that referenced this pull request Dec 13, 2022
… message (Titouan Galopin)

This PR was merged into the 6.2 branch.

Discussion
----------

[Console] Fix missing command not matching namespace error message

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix for #47750
| License       | MIT
| Doc PR        | -

Following #47750, running a command with an exception not related to the console (for instance fatal error) could end up in a situation where the error handling code doesn't stop the execution flow and result in:

```
In Application.php line 307:

  [ErrorException]
  Warning: Undefined variable $command
```

This fixes this behavior by throwing the original exception when no other error handling cases could handle the problem.

Commits
-------

1e7202d Fix missing command not matching namespace error message
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.

6 participants