Skip to content

Commit

Permalink
feat: improve RatioListCommand (add option "format")
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris8934 committed Jan 30, 2024
1 parent 85254f0 commit f94e08f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Command/RatioListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class RatioListCommand extends Command
{
private string $format;
private string $format = 'txt';

public function __construct(private PairManagerInterface $pairManager)
{
Expand Down Expand Up @@ -81,8 +81,8 @@ private function display(OutputInterface $output, SymfonyStyle $io): int
$ratioList = $this->pairManager->getRatioList();

return match ($this->format) {
'txt' => $this->displayTxt($ratioList, $output, $io),
'json' => $this->displayJson($ratioList, $output),
'txt' => $this->displayTxt($ratioList, $output, $io),
'json' => $this->displayJson($ratioList, $output),
'table' => $this->displayTable($ratioList, $output, $io),
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
};
Expand All @@ -91,7 +91,10 @@ private function display(OutputInterface $output, SymfonyStyle $io): int
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$this->format = $input->getOption('format') ?? 'txt';

/** @var string $format */
$format = $input->getOption('format') ?? 'txt';
$this->format = $format;

return $this->display($output, $io);
}
Expand Down

0 comments on commit f94e08f

Please sign in to comment.