feat: add interactive menu for managing MageForge Inspector actions - #240
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances the mageforge:theme:inspector CLI command to support an interactive mode when no action argument is provided, improving usability for developers running the command in a real terminal.
Changes:
- Made the
actionargument optional and updated help text to describe interactive behaviour. - Added an interactive action selector using
Laravel\Prompts\SelectPrompt, with fallback to showing status in non-interactive environments. - Updated execution flow to prompt for “enable/disable/status” when appropriate.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/Console/Command/Dev/InspectorCommand.php:154
promptAction()uses Laravel Prompts but doesn’t set/reset the prompt environment (used elsewhere for Docker/DDEV compatibility) and only restores TTY on the success path. If the prompt throws, the terminal may be left in a bad state and env vars won’t be restored.
try {
$selection = $prompt->prompt();
\Laravel\Prompts\Prompt::terminal()->restoreTty();
return is_string($selection) ? $selection : null;
} catch (\Exception $e) {
src/Console/Command/Dev/InspectorCommand.php:103
- The new “no action provided” behaviour (interactive prompt when possible; status fallback when non-interactive) isn’t covered by unit tests. There are existing unit tests for this command, so this new branch should be exercised to prevent regressions.
// No action given: show interactive menu, fall back to status in non-interactive mode
if ($action === '') {
if (!$this->isInteractiveTerminal($output)) {
return $this->showStatus();
}
$selectedAction = $this->promptAction();
if ($selectedAction === null) {
return Cli::RETURN_FAILURE;
}
$action = $selectedAction;
}
src/Console/Command/Dev/InspectorCommand.php:62
- Help text says the interactive menu is to “enable or disable” the inspector, but the menu also includes a “status” option; the help should reflect all available actions.
<info>php %command.full_name%</info>
Show an interactive menu to enable or disable the inspector
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Console/Command/Dev/InspectorCommand.php:101
- When the interactive menu returns null (e.g. user cancels), the command exits with failure but prints no message. Adding a short warning/error improves UX and makes failures clearer in logs.
if ($selectedAction === null) {
return Cli::RETURN_FAILURE;
}
src/Console/Command/Dev/InspectorCommand.php:94
- The interactive menu is only gated by isInteractiveTerminal($output). This ignores Symfony's --no-interaction flag (InputInterface::isInteractive() becomes false), which can cause the command to block on a prompt in scripted/non-interactive runs even when the terminal is a real TTY.
if (!$this->isInteractiveTerminal($output)) {
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Console/Command/Dev/InspectorCommand.php:152
setPromptEnvironment()is called after theSelectPromptis constructed. In other commands (and AbstractCommand), the prompt environment is set before building the prompt so terminal dimensions/TERM are in place for prompt setup and rendering. Consider moving the environment setup above thenew SelectPrompt(...)construction to avoid subtle rendering issues in Docker/DDEV terminals.
// Set environment variables for Laravel Prompts (Docker/DDEV compatibility)
$this->setPromptEnvironment();
src/Console/Command/Dev/InspectorCommand.php:162
- In the
finallyblock, ifPrompt::terminal()->restoreTty()throws,resetPromptEnvironment()won’t run and the process environment can be left mutated (COLUMNS/LINES/TERM). Wrap the TTY restore in its own try/catch so prompt env reset always happens.
} finally {
\Laravel\Prompts\Prompt::terminal()->restoreTty();
$this->resetPromptEnvironment();
}
This pull request enhances the
InspectorCommandto support an interactive mode for selecting actions, improving user experience when no action argument is provided. The command now presents a menu for enabling, disabling, or checking the status of the MageForge Inspector, with a fallback to status in non-interactive environments. The most important changes are:Interactive Command Enhancements:
actionargument optional in theInspectorCommandso that if omitted, the user is presented with an interactive menu to choose an action. The help text was updated to reflect this new behavior.promptActionmethod usingLaravel\Prompts\SelectPromptto display an interactive menu for selecting "enable", "disable", or "status". The menu shows the current inspector status and provides keyboard navigation hints.Laravel\Prompts\SelectPromptclass to support the new interactive prompt functionality.