Node Symfony Console
This is a straight port of Symfony's Console Component v5.1. Augmented with the spinner functionality largely inspired by alecrabbit/php-console-spinner
Although fully functional, this is very much WIP.
Usage
Eventually we will write ported documentation. For now follow Console Component v5.1 documentation and translate the examples to JS.
// Most used classes are accessible as direct importsconst Terminal Application SingleCommandApplication Command Question ConfirmationQuestion ChoiceQuestion ProgressBar ProgressIndicator Table TableStyle Output Input InputArgument InputOption Spinner SpinnerFrames = ;
// All of the underlying classes can be accessed throught the console export. Follow the// original PhP namespace class paths. const console = ; // PHP Class \Symfony\Component\Console\Helper\HelperSetconst HelperSet = consolehelperHelperSet; // PHP Class \Symfony\Component\Console\Tester\CommandTesterconst CommmandTester = consoletesterCommandTester;
Hello World Example
Create a command
const Command InputArgument ConfirmationQuestion = ; static { return 'foo:helloworld'; } { this // the short description shown while running "node bin/console list" // the full command description shown when running the command with // the "--help" option ; } async { // Do something asynchronous like an API call or // asking a question const q = '<info>Are you leaving</info> (y/n): '; const leaving = await this; let greet = ` `; const lastName = input; if lastName greet = ` `; output; return 1; } moduleexports = GreetCommand;
Create a application and include the command. This can be any file IE: bin/console.js
const Application = ;const GreetCommand = ; const application = ;application;application;
Run the command:
$ node bin/console.jsConsole Tool Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1
Known omissions and limitations
Porting changes:
- Interfaces have been removed
- Abstract classes have been converted to regular classes
- PhP associative arrays do not always translate well to JS {} or []
- Itterable support is spotty, WIP
- Node requires not separate multibyte support for most situations, in general these functions were stripped
- Terminal Capability detection was quite specific to PhP, tested on Mac, on other terminals millage may vary
- Exception classes have been renamed to Error
- Not all Exceptions types have been ported, instead using generic throw Error
- Verbosity constants can be found in Output
const {Output} = require('node-symfony-console')
Omissions: Following have not (yet) been ported
Contributing
Contributions are welcome! Most of the tests have been written in JS.
Resources
Credits
This library is converted from Symfony's Console Component: Find sources and license at https://github.com/symfony/component
This library uses code from the spinner library Find sources and license at https://github.com/alecrabbit/php-console-spinner