vanengers/symfony-console-command-lib

Symfony Console Command library

v1.3.1 2024-04-23 11:33 UTC

This package is auto-updated.

Last update: 2024-04-23 11:33:22 UTC


README

Library for Symfony console commands

Installation

composer require vanengers/symfony-console-command-lib

Usage

class MyCommand extends AbstractConsoleCommand {}

Implement the abstract methods and you are good to go.

executeCommand():

the method that actually executes the command, do not use the execute() method from the parent class

getCommandName():

this should return the name of the command for the command line

getCommandDescription():

this should return a description of the command for the command line

getOptions():

this should return an array of options for the command line Each Option will be checked for default value and value inputed by the user Look at the example

only simple types are expected: array, bool, int, string

All options are input as options and not arguments. So all options could be defaulted.

You could implicitly require an input by setting the default value to null and setting the required flag to true

Validators

You can add validators to the Option in getOptions

new Option('config', 'name param', 'string', null, true, null, [
    new FileExistsValidator(),
])

By setting default value to null and required to true, you can require a file that exists. Settting up validators is easy, just create a class that implements the IParamValidate interface and add it to the option.