/** * Show operation details for a workflow * * ## OPTIONS * [--workflow_id] * : Uuid of workflow to show * [--site=<site>] * : Site from which to list workflows * [--latest-with-logs] * : Display the most-recent workflow with logs * * @subcommand show */ public function show($args, $assoc_args) { $site = $this->sites->get(Input::siteName(array('args' => $assoc_args))); if (isset($assoc_args['workflow_id'])) { $workflow_id = $assoc_args['workflow_id']; $model_data = (object) array('id' => $workflow_id); $workflow = $site->workflows->add($model_data); } elseif (isset($assoc_args['latest-with-logs'])) { $site->workflows->fetch(array('paged' => false)); $workflow = $site->workflows->findLatestWithLogs(); if (!$workflow) { $this->log()->info('No recent workflow has logs'); return; } } else { $site->workflows->fetch(array('paged' => false)); $workflows = $site->workflows->all(); $workflow = Input::workflow(compact('workflows')); } $workflow->fetchWithLogs(); $workflow_data = $workflow->serialize(); if (Terminus::getConfig('format') == 'normal') { unset($workflow_data['operations']); $this->output()->outputRecord($workflow_data); $operations = $workflow->operations(); if (count($operations)) { // First output a table of operations without logs $operations_data = array_map(function ($operation) { $operation_data = $operation->serialize(); unset($operation_data['id']); unset($operation_data['log_output']); return $operation_data; }, $operations); $this->output()->outputRecordList($operations_data, array('description' => 'Operation Description')); // Second output the logs foreach ($operations as $operation) { if ($operation->has('log_output')) { $log_msg = sprintf("\n------ %s ------\n%s", $operation->description(), $operation->get('log_output')); $this->output()->outputValue($log_msg); } } } else { $this->output()->outputValue('Workflow has no operations'); } } else { $this->output()->outputRecord($workflow_data); } }
/** * Show operation details for a workflow * * ## OPTIONS * [--workflow_id] * : Uuid of workflow to show * [--site=<site>] * : Site from which to list workflows * * @subcommand show */ public function show($args, $assoc_args) { $site = $this->sites->get(Input::sitename($assoc_args)); $workflow = Input::workflow($site, $assoc_args, 'workflow_id'); $workflow_data = $workflow->serialize(); if (Terminus::getConfig('format') == 'normal') { $operations_data = $workflow_data['operations']; unset($workflow_data['operations']); $this->output()->outputRecord($workflow_data); if (count($operations_data)) { $this->log()->info('Workflow operations:'); $this->output()->outputRecordList($operations_data); } else { $this->log()->info('Workflow has no operations'); } } else { $this->output()->outputRecordList($workflow_data); } }
/** * Show quicksilver logs from a workflow * * ## OPTIONS * [--latest] * : Display the most-recent workflow with logs * [--workflow_id] * : Uuid of workflow to fetch logs for * [--site=<site>] * : Site from which to list workflows * * @subcommand logs */ public function logs($args, $assoc_args) { $site = $this->sites->get(Input::sitename($assoc_args)); if (isset($assoc_args['latest'])) { $site->workflows->fetchWithOperationsAndLogs(array('paged' => false)); $workflow = $site->workflows->findLatestWithLogs(); if (is_null($workflow)) { return $this->failure('No recent workflows contain logs'); } } else { $site->workflows->fetchWithOperations(array('paged' => false)); $workflows = $site->workflows->all(); $workflow = Input::workflow($workflows, $assoc_args, 'workflow_id'); $workflow->fetchWithLogs(); } if (Terminus::getConfig('format') == 'normal') { $operations = $workflow->operations(); if (count($operations) == 0) { $this->log()->info('Workflow has no operations'); return; } $operations_with_logs = array_filter($operations, function ($operation) { return $operation->get('log_output'); }); if (count($operations_with_logs) == 0) { $this->log()->info('Workflow has no operations with logs'); return; } foreach ($operations as $operation) { if ($operation->get('log_output')) { $operation_data = $operation->serialize(); $this->output()->outputRecord($operation_data); } } } else { $workflow_data = $workflow->serialize(); $operations_data = $workflow_data['operations']; $this->output()->outputRecordList($operations_data); } }