Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introducing survos/command-bundle, a web interface for console commands #55

Closed
tacman opened this issue Oct 16, 2023 · 8 comments
Closed

Comments

@tacman
Copy link
Contributor

tacman commented Oct 16, 2023

This is more a discussion than an issue, but discussions aren't enabled for this repo.

I've been working on a way to run commands from a web interface, mostly to take advantage of the debug toolbar, but also because sometimes I want access to a command without logging into the server. It uses console-extra's runCommand() method.

For example, in the Symfony demo application, there's a --send-to option, but it's hard to debug from the command line. Calling it from the browser shows the emails sent in the debug toolbar. Also, sometimes I want to add and list users from the website without writing custom controllers.

Here's a quick example exposing the app commands in the Symfony Demo

symfony new --demo command-demo && cd command-demo
# bump to the latest version of Symfony 6.3, use whatever version of you have installed
sed -i 's/"php": "8.1.0"//' composer.json 
sed -i 's/"require": "6.3"/"require": "^6.3"/' composer.json
composer config extra.symfony.allow-contrib true
composer update 
# allow recipes, waiting for PR approval
export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes-contrib/flex/pull-1548/index.json

composer req survos/command-bundle
yarn install && yarn dev
symfony server:start -d
symfony open:local  --path admin/commands

I also have a make:invokable-command that of course works hand-in-hand with this.

I wanted to first thank you for releasing console-extra and ask your feedback on my bundle. I don't yet have arrays working from the web interface.

@kbond
Copy link
Member

kbond commented Oct 24, 2023

Neat bundle. One quick suggestion, perhaps enable running commands asynchronously with the new RunCommandMessage in 6.4.

@tacman
Copy link
Contributor Author

tacman commented Oct 24, 2023

Yes, that would be pretty cool.

And then I guess if the messageHandler could pass the results back to the browser...

@kbond
Copy link
Member

kbond commented Oct 24, 2023

And then I guess if the messageHandler could pass the results back to the browser...

That would be the difficult part...

@jdreesen
Copy link
Contributor

@tacman
Copy link
Contributor Author

tacman commented Oct 24, 2023

Yes, I saw that yesterday! Still, I use my command bundle all the time for getting readable dd() and dump()'s.

@tacman
Copy link
Contributor Author

tacman commented Dec 30, 2023

Indeed, the RunCommandMessageHandler looks really interesting.

How can I capture the output though? It's a final class, so I shouldn't extend it.

    public function dispatchCommand(string $cli) {
        $envelope = $this->bus->dispatch(new RunCommandMessage($cli));
    }

I've configured the handler to be async:

        routing:
            App\Message\DownloadImage: async
            Symfony\Component\Console\Messenger\RunCommandMessage: async
            App\Message\TranslationMessage: low

Now when I consume the message, I'd like to get the $ouput->fetch(), which is returned in the handler

        return new RunCommandContext($message, $exitCode, $output->fetch());
bin/console messenger:consume async --limit 1 -vvv

Is there a way to get the output? The command is running but I'm not sure how to see the results. Even if I tweak my command to use $logger instead of $io, I'm not seeing the output I expect.

@kbond
Copy link
Member

kbond commented Jan 2, 2024

In your case, you'd need to listen to the WorkerMessageHandledEvent and get/handle the output that way.

@tacman
Copy link
Contributor Author

tacman commented Jan 2, 2024

Perfect, thanks!

@tacman tacman closed this as completed Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants