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
- Create a command with option parameters in the signature:
public function getSignature(): string
{
return 'mycommand subcommand {--count=1:Number of items} {--cascade:Enable cascade}';
}
- Register the command via
ConsoleStrategy::registerCommand()
- Run
wp mycommand subcommand --help or attempt to use the command
- Observe WP-CLI warnings about invalid synopsis parts
The
ConsoleStrategy::parseSignature()method inlib/Strategies/ConsoleStrategy.phpcontains 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):
This only removes a single leading dash from parameter names, so
--countbecomes-countinstead ofcount.Expected behavior:
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:While commands still function, these warnings indicate malformed synopsis data that could lead to incorrect help documentation or parameter validation issues.
Steps to Reproduce
ConsoleStrategy::registerCommand()wp mycommand subcommand --helpor attempt to use the command