Skip to content

Conversation

mrsdizzie
Copy link
Member

@mrsdizzie mrsdizzie commented Mar 20, 2024

This would be a first step towards addressing #5838 and including details on when a specific command is run in the handbook documentation.

I've added the output to the help command as well so there will be parity between that and the handbook.

If the parent command defines a @when tag, that is passed down to all subcommands. If a subcommand has its own @when tag, it will take the place of the parent tag. If there is no @when tag defined for a parent or subcommand, it won't show any hook information with the existing assumption that everything runs on the default hook unless otherwise specified.

So now a command like wp help db reset would output:

NAME

  wp db reset

DESCRIPTION

  Removes all tables from the database.

  This command runs when the 'after_wp_config_load' hook is called, after wp-config.php has been loaded into scope.

SYNOPSIS

  wp db reset [--dbuser=<value>] [--dbpass=<value>] [--yes] [--defaults]

  Runs `DROP_DATABASE` and `CREATE_DATABASE` SQL statements using
  `DB_HOST`, `DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
  specified in wp-config.php.

Where the after_wp_config_load hook is inherited from the parent db command.
And wp help db size would show:

NAME

  wp db size

DESCRIPTION

  Displays the database name and size.

  This command runs when the 'after_wp_load' hook is called, just after the WP load process has completed.

SYNOPSIS

  wp db size [--size_format=<format>] [--tables] [--human-readable] [--format=<format>] [--scope=<scope>] [--network] [--decimals=<decimals>] [--all-tables-with-prefix] [--all-tables] [--order=<order>] [--orderby=<orderby>]

  Display the database name and size for `DB_NAME` specified in wp-config.php.
  The size defaults to a human-readable number.

Since it defines a different hook to run on.

This would be a first step towards addressing wp-cli#5838 and including
details on when a specific command is run in the handbook documentation.

I've added the output to the help command as well so there will be
parody between that and the handbook.
@mrsdizzie mrsdizzie requested a review from a team as a code owner March 20, 2024 17:21
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
* @return string|null
*/

function get_hook_description( $hook ) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this just be a private method on the Help_Command class?

Copy link
Member Author

@mrsdizzie mrsdizzie Apr 26, 2024

Choose a reason for hiding this comment

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

I believe this needs to be a public util function because the handbook project doesn't use the output of wp help and needs similar code added there as well in order to have consistency. Was going to do a PR for that one next after this is added.

Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Can we include some tests too? (Just some basic smoke test for it)

This string can wrap depending on settings, so hardcode various column
numbers for consistency.
@mrsdizzie
Copy link
Member Author

@danielbachhuber tests added thanks!

Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Thanks, @mrsdizzie ! I made a few small tweaks you might like to look through ^

@danielbachhuber danielbachhuber merged commit 6d78633 into wp-cli:main Apr 27, 2024
@mrsdizzie
Copy link
Member Author

@danielbachhuber looks great, thanks much!

mrsdizzie added a commit to mrsdizzie/handbook that referenced this pull request Apr 27, 2024
When a command specifies a non-default hook, include those details in
handbook documentation for the command.

Related: wp-cli/wp-cli#5921

Fixes: wp-cli/wp-cli#5838
danielbachhuber pushed a commit to wp-cli/handbook that referenced this pull request Apr 29, 2024
When a command specifies a non-default hook, include those details in
handbook documentation for the command.

Related: wp-cli/wp-cli#5921

Fixes: wp-cli/wp-cli#5838
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.

3 participants