In a command's configure() method, add the --format option:
Table::addFormatOption($this->getDefinition());
In a command's execute() method, build and display the table:
$table = new Table($input, $output);
$header = ['Column 1', 'Column 2', 'Column 3'];
$rows = [
['Cell 1', 'Cell 2', 'Cell 3'],
['Cell 4', 'Cell 5', 'Cell 6'],
];
$table->render($rows, $header);
Show file
Open project: commerceguys/platform-cli
Class Usage Examples
Property | Type | Description | |
---|---|---|---|
$input | |||
$output |
Method | Description | |
---|---|---|
__construct ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) | ||
addFormatOption ( Symfony\Component\Console\Input\InputDefinition $definition ) | Add the --format option to a command's input definition. | |
formatIsMachineReadable ( ) : boolean | Find whether the user wants machine-readable output. | |
render ( array $rows, array $header = [] ) | Render a table of data to output. | |
renderSimple ( array $values, array $propertyNames ) | Render an single-dimensional array of values, with their property names. |
Method | Description | |
---|---|---|
getFormat ( ) : string | null | Get the user-specified format. | |
renderCsv ( array $rows, array $header, string $delimiter = ',', string $enclosure = '"' ) | Render CSV output. | |
renderTable ( array $rows, array $header ) | Render a Symfony Console table. |
public __construct ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) | ||
$input | Symfony\Component\Console\Input\InputInterface | |
$output | Symfony\Component\Console\Output\OutputInterface |
public static addFormatOption ( Symfony\Component\Console\Input\InputDefinition $definition ) | ||
$definition | Symfony\Component\Console\Input\InputDefinition |
public formatIsMachineReadable ( ) : boolean | ||
return | boolean | True if the user has specified a machine-readable format via the --format option (e.g. 'csv' or 'tsv'), false otherwise. |
public renderSimple ( array $values, array $propertyNames ) | ||
$values | array | |
$propertyNames | array |
protected renderTable ( array $rows, array $header ) | ||
$rows | array | |
$header | array |