Platformsh\Cli\Util\Table::formatIsMachineReadable PHP Method

formatIsMachineReadable() public method

Find whether the user wants machine-readable output.
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 function formatIsMachineReadable()
    {
        return in_array($this->getFormat(), ['csv', 'tsv']);
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $environment = $this->getSelectedEnvironment();
     $startsAt = null;
     if ($input->getOption('start') && !($startsAt = strtotime($input->getOption('start')))) {
         $this->stdErr->writeln('Invalid date: <error>' . $input->getOption('start') . '</error>');
         return 1;
     }
     $limit = (int) $input->getOption('limit');
     $activities = $environment->getActivities($limit, $input->getOption('type'), $startsAt);
     if (!$activities) {
         $this->stdErr->writeln('No activities found');
         return 1;
     }
     $table = new Table($input, $output);
     $rows = [];
     foreach ($activities as $activity) {
         $description = $activity->getDescription();
         if (!$table->formatIsMachineReadable()) {
             $description = wordwrap($description, 40);
         }
         $rows[] = [$activity->id, date('Y-m-d H:i:s', strtotime($activity['created_at'])), $description, $activity->getCompletionPercent(), ActivityUtil::formatState($activity->state)];
     }
     if (!$table->formatIsMachineReadable()) {
         $this->stdErr->writeln("Activities for the environment <info>" . $environment->id . "</info>");
     }
     $headers = ['ID', 'Created', 'Description', '% Complete', 'State'];
     $table->render($rows, $headers);
     return 0;
 }
All Usage Examples Of Platformsh\Cli\Util\Table::formatIsMachineReadable