adventofcode/src/Puzzle.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2021-12-01 22:46:07 +01:00
<?php
namespace trizz\AdventOfCode;
2021-12-01 22:46:07 +01:00
2022-11-29 19:52:02 +01:00
use PhpPkg\CliMarkdown\CliMarkdown;
2021-12-01 22:46:07 +01:00
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
2022-11-29 19:52:02 +01:00
final class Puzzle extends Command
2021-12-01 22:46:07 +01:00
{
protected function configure(): void
{
$this
->setName('puzzle')
2022-11-29 19:52:02 +01:00
->setDescription('Show the puzzle description.')
->addArgument('day', InputArgument::REQUIRED, 'The day number.')
->addArgument('year', InputArgument::OPTIONAL, 'The year', date('y'));
2021-12-01 22:46:07 +01:00
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$contents = file_get_contents(
sprintf(
'%s/../data/Y%d/day%s/puzzle.md',
__DIR__,
$input->getArgument('year'),
(int) $input->getArgument('day')
)
);
2022-11-29 19:52:02 +01:00
if (!$contents) {
$output->writeln('Can not read puzzle.');
return Command::FAILURE;
}
$rendered = (new CliMarkdown())->render($contents);
2021-12-01 22:46:07 +01:00
$output->writeln($rendered);
return Command::SUCCESS;
}
}