Skip to content

fix: listCommands parser not detecting commands and actions#2

Open
restarter wants to merge 1 commit intoArtMin96:mainfrom
restarter:fix/list-commands-parser
Open

fix: listCommands parser not detecting commands and actions#2
restarter wants to merge 1 commit intoArtMin96:mainfrom
restarter:fix/list-commands-parser

Conversation

@restarter
Copy link

Problem

The yii_list_commands tool returns empty results because the parser logic has bugs:

  1. Command detection - Line 96 checks !trimmed.includes(' ') but command lines like:

    - cache                                           Class CacheController
    

    contain multiple spaces for alignment, so this condition filters them out.

  2. Action detection - Line 109 checks trimmed.startsWith(' ') but after trim() there are no leading spaces, so action lines are never detected.

Solution

  • Remove the !trimmed.includes(' ') check for commands - they're identified by starting with -
  • Use original line instead of trimmed for indentation checks
  • Use trimmed only for content parsing after indentation is verified

Testing

Before fix:

Available Yii2 Console Commands:

(empty)

After fix:

Available Yii2 Console Commands:

### cache
• **cache** - Class CacheController
  - cache/flush
  - cache/flush-all
  ...

The parser was using trimmed line to check for indentation, but trim()
removes leading spaces. This caused:

1. Command detection failed because trimmed.includes('    ') was true
   for command lines with aligned descriptions (multiple spaces)

2. Action detection failed because trimmed.startsWith('    ') was
   always false after trim() removed leading spaces

Fix: Use original line for indentation checks, trimmed for content parsing.
@restarter
Copy link
Author

Note: I kept the 8-space check (\!line.startsWith(' ')) to minimize changes, though it seems unnecessary - Yii2's HelpController only uses 2-space and 4-space indentation based on the source code. Feel free to remove it if you prefer cleaner code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant