livecoding-console/src/Deblan/Command/ListCommand.php

74 lines
2.2 KiB
PHP

<?php
namespace Deblan\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\Command;
use Exception;
class ListCommand extends Command
{
protected function configure()
{
$this
->setName('streams')
->setDescription('List available streams.')
->addOption('category', null, InputOption::VALUE_REQUIRED, '')
->setHelp("The <info>%command.name%</info> lists live streams");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$liveCoding = $this->getApplication()->getContainer()['livecoding'];
try {
$streams = $liveCoding->getStreams();
foreach ($streams as $stream) {
$output->writeln(sprintf(
'<comment>%s</comment>',
$stream->getTitle()
));
$output->writeln(sprintf(
'<comment>%s</comment>',
str_repeat('-', mb_strlen($stream->getTitle()))
));
$output->writeln(sprintf(
'<info>Author:</info> %s',
$stream->getAuthor()
));
if (count($stream->getLanguages())) {
$output->writeln(sprintf(
'<info>Languages:</info> %s',
implode(', ', $stream->getLanguages())
));
$output->writeln(sprintf(
'<info>Difficulty:</info> %s',
$stream->getDifficulty()
));
}
$output->writeln(sprintf(
'<info>URL:</info> %s',
$stream->getUrl()
));
$output->writeln(sprintf(
'<info>Views:</info> %d',
$stream->getViews()
));
$output->writeln('');
}
} catch (Exception $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}
}