Problem/Motivation

Invokable commands don't show their usage examples in their help. This is a bug in the console compiler pass.

Steps to reproduce

Run dr quick-start -h and note that usages are not shown.

Testing against Symfony 8.1
  • Clone the issue fork and checkout the merge request
  • composer install in testing environment
  • ./vendor/bin/dr to list commands. Copy output to a file.
  • COMPOSER_ROOT_VERSION=dev-main composer update -W
  • ./vendor/bin/dr to list commands. Compare output to previous invocation of that command.
  • Run test command above to assert usages

Proposed resolution

Populate the service tag. This enables Symfony's \Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass to find the usages and populate the console.command_loader service arguments with them.

Remaining tasks

Test against Symfony 8.1 - #3607060: ConsoleCompilerPass incompatible with symfony/console ≥ 8.1

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

N/A

Issue fork drupal-3606744

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

moshe weitzman created an issue. See original summary.

moshe weitzman’s picture

Title: Invokable commands dont show their usages » Invokable commands dont show their usages in help
Issue summary: View changes

ressa’s picture

Thanks, this patch fixes the missing Usage examples, and I can for example see how to install multiple modules, using comma-separated syntax with patch from #3594334: Add a module and theme install command, where the two examples at the bottom (ex:install views,views_ui and ex:install claro) are omitted without this patch. So functionally this is RTBC, maybe someone else can review the code?

$ dr ex:install -h
Description:
  Installs one or more modules or themes.

Usage:
  ex:install [options] [--] <extensions>
  exin
  pm:install
  pm:enable
  enable
  en
  ex:install views,views_ui
  ex:install claro
[...]
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative, +Needs Review Queue Initiative

Came here from #3607060: ConsoleCompilerPass incompatible with symfony/console ≥ 8.1

   if ($attribute->help !== NULL) {
          $tag['help'] = $attribute->help;
        }
        if ($attribute->usages) {
          $tag['usages'] = $attribute->usages;
        }

This seems fine but maybe a follow up to make that more dynamic? Example what if another attribute is added, someone will have to remember to udpate this snippet right?

Can't run the test-only job so did it locally

Failed asserting that 'Description:\n
  An example invokable command.\n
\n
Usage:\n
  example:invokable\n
\n
Options:\n
  -h, --help            Display help for the given command. When no command is given display help for the list command\n
      --silent          Do not output any message\n
  -q, --quiet           Only errors are displayed. All other output is suppressed\n
  -V, --version         Display this application version\n
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output\n
  -n, --no-interaction  Do not ask any interactive question\n
      --url=URL         A base URL (e.g. example.com). Used for building links, selecting a multi-site, etc.\n
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n
' [ASCII](length: 748) contains "example:invokable foo" [ASCII](length: 21).
/var/www/html/core/tests/Drupal/KernelTests/Core/Console/ConsoleTest.php:121

btw SLOW kernel test, least locally.

per the manual test in #4 also this appears to be working.

mradcliffe’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

I added some testing instructions related to Symfony 8.1.

However, I was running ./vendor/bin/dr quick-start -h on a clean core checkout and it displayed the usage already?

Are there specific steps to reproduce?

mradcliffe’s picture

On de0a865f3a8, with either environment:

- cloned core directly
- using core/recommended-project (via joachim-n/drupal-core-development-project)

 ./vendor/bin/dr quick-start -h 
Description:
  Installs a Drupal site and starts a web server for local testing or development.

Usage:
  quick-start [options] [--] <install-profile-or-recipe>
  quick-start demo_umami --langcode fr
  quick-start standard --site-name QuickInstall --host localhost --port 8080
  quick-start minimal --host my-site.com --port 80
  quick-start core/recipes/standard --site-name MyDrupalRecipe

Arguments:
  install-profile-or-recipe  Install profile or recipe directory from which to install the site.

Options:
      --langcode=LANGCODE    The language to install the site in. Defaults to 'en'. [default: "en"]
      --password=PASSWORD    Set the administrator password. Defaults to a randomly generated password.
      --site-name=SITE-NAME  Set the site name. [default: "Drupal"]
      --host=HOST            Provide a host for the server to run on. [default: "127.0.0.1"]
      --port=PORT            Provide a port for the server to run on (determined automatically if none is supplied).
  -s, --suppress-login       Disable opening a login URL in a browser.
  -h, --help                 Display help for the given command. When no command is given display help for the list command
      --silent               Do not output any message
  -q, --quiet                Only errors are displayed. All other output is suppressed
  -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
      --url=URL              A base URL (e.g. example.com). Used for building links, selecting a multi-site, etc.
  -e, --env=ENV              The Environment name. [default: "prod"]
      --no-debug             Switches 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
xmacinfo’s picture

In your sample, the quick-start --help shows the usage, but not the help part.

A command that shows both usage and help is list:

dr list -h
Description:
  List commands

Usage:
  list [options] [--] [<namespace>]

Arguments:
  namespace             The namespace name

Options:
      --raw             To output raw command list
      --format=FORMAT   The output format (txt, xml, json, or md) [default: "txt"]
      --short           To skip describing commands' arguments
  -h, --help            Display help for the given command. When no command is given display help for the list command
      --silent          Do not output any message
  -q, --quiet           Only errors are displayed. All other output is suppressed
  -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
      --url=URL         A base URL (e.g. example.com). Used for building links, selecting a multi-site, etc.
  -e, --env=ENV         The Environment name. [default: "prod"]
      --no-debug        Switches 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

Help:
  The list command lists all commands:

    /Users/jrblier/web/Sites/2017.local.xmacinfo.com/vendor/bin/dr list

  You can also display the commands for a specific namespace:

    /Users/jrblier/web/Sites/2017.local.xmacinfo.com/vendor/bin/dr list test

  You can also output the information in other formats by using the --format option:

    /Users/jrblier/web/Sites/2017.local.xmacinfo.com/vendor/bin/dr list --format=xml

  It's also possible to get raw list of commands (useful for embedding command runner):

    /Users/jrblier/web/Sites/2017.local.xmacinfo.com/vendor/bin/dr list --raw

Not sure if we need an help block for each command.

moshe weitzman’s picture

This seems fine but maybe a follow up to make that more dynamic?

That would depend on what change we would be reacting to Symfony Console. In current Console, the code here is sufficient.

quick-start's help output looks OK to me. It doesn't have any long-form help. Sorry I picked an incorrect command for testing this. A better example is in #3594334: Add a module and theme install command - it not showing its 3 usages when you run vendor/bin/dr ex:install -h. The usages do show when you layer this MR on top. If that sounds like a pain to test, lets get that one in :)