consolidation/annotated-command
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
consolidation/output-formatters | 4.5.0 | 91.97 kB | MIT | prod | |
psr/log | 3.0.0 | 6.77 kB | MIT | prod dev | |
symfony/console | v6.4.6 | 182.96 kB | MIT | prod | |
symfony/event-dispatcher | v6.4.3 | - | MIT | prod dev | |
symfony/finder | v6.4.0 | 29.28 kB | MIT | prod |
The Consolidation Annotated Command is a powerful package that simplifies the creation of Symfony Console commands. It uses annotations or PHP 8 attributes to define the properties of your command such as its arguments, options, and so forth. This package is currently being used in notable projects such as Robo, Drush, and Terminus.
To use the consolidation/annotated-command, you first have to pull the package's latest version into your project using composer. Add the following line to your composer.json file:
"require": {
"consolidation/annotated-command": "^4"
}
Then run composer update
to download and integrate the library into your project. Once done, you can start creating annotated command classes.
Here is a code example of how you can use the package:
class MyCommandClass
{
/**
* This is the my:echo command
*
* This command will concatenate two parameters. If the --flip flag
* is provided, then the result is the concatenation of two and one.
*
* @command my:echo
* @param string $one The first parameter.
* @param string $two The other parameter.
* @param bool $flip The "flip" option
* @option flip Whether or not the second parameter should come first in the result.
* @aliases c
* @usage bet alpha --flip
* Concatenate "alpha" and "bet".
*/
public function myEcho($one, $two, $flip = false)
{
if ($flip) {
return "{$two}{$one}";
}
return "{$one}{$two}";
}
}
This example code shows how consolidation/annotated-command does its magic. By just simply defining and decorating your command method with relevant annotations, you can specify the command, its arguments, options, aliases, and even usage examples.
The official documentation for the consolidation/annotated-command library can be found on its GitHub repository at the following URL: https://github.com/consolidation/annotated-command. The documentation provides a comprehensive guide on the API usage, a rundown of the hooks available, and how you can handle standard input and output for your commands. It also contains example usages that'll help you understand how to effectively use the library.