|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace mglaman\DrupalOrgCli\Command\Issue; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Input\InputArgument; |
| 6 | +use Symfony\Component\Console\Input\InputInterface; |
| 7 | +use Symfony\Component\Console\Input\InputOption; |
| 8 | +use Symfony\Component\Console\Output\OutputInterface; |
| 9 | +use mglaman\DrupalOrg\IssueTrait; |
| 10 | + |
| 11 | +class Show extends IssueCommandBase |
| 12 | +{ |
| 13 | + use IssueTrait; |
| 14 | + |
| 15 | + /** |
| 16 | + * {@inheritdoc} |
| 17 | + */ |
| 18 | + protected function configure(): void |
| 19 | + { |
| 20 | + $this |
| 21 | + ->setName('issue:show') |
| 22 | + ->addArgument('nid', InputArgument::REQUIRED, 'The issue node ID') |
| 23 | + ->addOption( |
| 24 | + 'format', |
| 25 | + 'f', |
| 26 | + InputOption::VALUE_OPTIONAL, |
| 27 | + 'Output options: text, json. Defaults to text.', |
| 28 | + 'text' |
| 29 | + ) |
| 30 | + ->setDescription('Show a given issue information.'); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * {@inheritdoc} |
| 35 | + */ |
| 36 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 37 | + { |
| 38 | + $nid = $this->stdIn->getArgument('nid'); |
| 39 | + $issue = $this->client->getNode($nid); |
| 40 | + $issue_data = $issue->getContent(); |
| 41 | + $format = $this->stdIn->getOption('format'); |
| 42 | + |
| 43 | + if ($format == 'json') { |
| 44 | + $this->stdOut->writeln(json_encode($issue_data)); |
| 45 | + return 0; |
| 46 | + } |
| 47 | + // format option is text. |
| 48 | + $this->stdOut->writeln(sprintf('Title: %s', $issue->get('title'))); |
| 49 | + $this->stdOut->writeln(sprintf('Status: %s', $this->getIssueStatusLabel($issue->get('field_issue_status')))); |
| 50 | + $this->stdOut->writeln(sprintf('Project: %s', $issue_data->field_project->machine_name)); |
| 51 | + $this->stdOut->writeln(sprintf('Version: %s', $issue->get('field_issue_version'))); |
| 52 | + $this->stdOut->writeln(sprintf('Component: %s', $issue->get('field_issue_component'))); |
| 53 | + $this->stdOut->writeln(sprintf('Priority: %s', $this->getIssuePriorityLabel($issue->get('field_issue_priority')))); |
| 54 | + $this->stdOut->writeln(sprintf('Category: %s', $this->getIssueCategoryLabel($issue->get('field_issue_category')))); |
| 55 | + // Assigned field does not seem to be exposed on API. |
| 56 | + // TODO Convert to username. |
| 57 | + $this->stdOut->writeln(sprintf('Reporter: %s', $issue_data->author->id)); |
| 58 | + $this->stdOut->writeln(sprintf('Created: %s', date('r', $issue->get('created')))); |
| 59 | + $this->stdOut->writeln(sprintf('Updated: %s', date('r', $issue->get('changed')))); |
| 60 | + $this->stdOut->writeln(sprintf("\nIssue summary:\n%s", strip_tags($issue_data->body->value))); |
| 61 | + return 0; |
| 62 | + } |
| 63 | +} |
0 commit comments