Skip to content

GromNaN/symfony-console-demo

Repository files navigation

Symfony Console Demo

This project is a demonstration of symfony/console features.

To run the project with Docker.

With bash:

docker build -t myconsole . && docker run -it --rm myconsole bash -l

Or with fish:

docker build -t myconsole . && docker run -it --rm myconsole fish -l

Examples

Progress Bar

Progress Bar

See example FarmingCommand

Interactive questions

Commands can be interactive: ask questions.

The best practice is to define all arguments and options, so that the command can be used without interaction, and ask for all missing values in Command::interact. This is the last place where you can ask for missing options/arguments before validation.

See example AskColorCommand

Also, Symfony Demo's AddUserCommand

Secret Input

Read stdin

"Make every program a filter" is the last precept of the UNIX Philosophy by Mike Gancarz. A filter is a program that gets most of its data from stdin and writes its main results to stdout.

STDIN is an always open stream of input data that can be used inside commands. But this needs to be wrapped into the StreamableInputInterface::getStream for testing.

$stdin = ($input instanceof StreamableInputInterface ? $input->getStream() : null) ?? STDIN;

See example HeadCommand.

Render table

Rendering clickable hyperlinks is one of the most important missing features of Console apps and commands. Although most of the terminal emulators auto-detect URLs and allow to click on them with some key combination, it's not possible to render clickable text that points to some arbitrary URL.

See example ReleasesCommand

Signals are an inter-process communication mechanism used by console commands. A signal is an asynchronous notification sent to a process (or to a specific thread within the same process) in order to notify it of an event that occurred. For example, when you press Ctrl + C in a command, the operating system sends the SIGINT signal to it.

See example SignalCommand

Lock

Symfony Style or Custom Style

Using option resolver

About

Demo of symfony/console features to build rich command line utilities

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published