Skip to content

ConsoleStrategy::parseSignature incorrectly parses optional arguments #25

@alexstandiford

Description

@alexstandiford

The ConsoleStrategy::parseSignature() method in lib/Strategies/ConsoleStrategy.php contains a bug on line 112 that causes option parameters (those starting with --) to be incorrectly parsed, resulting in malformed WP-CLI synopsis entries.

Current behavior (line 112):

$name = Str::trimLeading($raw, '-');

This only removes a single leading dash from parameter names, so --count becomes -count instead of count.

Expected behavior:

$name = Str::trimLeading($raw, '--');

This correctly removes both leading dashes from parameter names.

Impact

When command signatures include option parameters like {--count=1:Description}, the generated WP-CLI synopsis contains invalid entries such as ---count (three dashes) instead of the expected --count (two dashes). This causes WP-CLI to emit warnings:

Warning: The `wp command-name` command has an invalid synopsis part: ---count

While commands still function, these warnings indicate malformed synopsis data that could lead to incorrect help documentation or parameter validation issues.

Steps to Reproduce

  1. Create a command with option parameters in the signature:
public function getSignature(): string
{
    return 'mycommand subcommand {--count=1:Number of items} {--cascade:Enable cascade}';
}
  1. Register the command via ConsoleStrategy::registerCommand()
  2. Run wp mycommand subcommand --help or attempt to use the command
  3. Observe WP-CLI warnings about invalid synopsis parts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions