-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.php
48 lines (44 loc) · 1.48 KB
/
cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once "vendor/autoload.php";
use Garden\Cli\Cli;
use mikeroq\AdventOfCode\Shared\Advent;
$cli = new Cli();
$advent = new Advent();
$cli->command('run')
->description('Run Advent of Code Challenges')
->opt('year:y', 'Specify a year to run/test', true, 'integer')
->opt('day:d', 'Specify a day to run/test', false, 'integer')
->command('test')
->description('Test Advent of Code Challenges')
->opt('year:y', 'Specify a year to run/test', true, 'integer')
->opt('day:d', 'Specify a day to run/test', false, 'integer');
try {
$args = $cli->parse($argv, true);
} catch (Exception $e) {
echo "There was an error: $e";
}
if (isset($args)) {
$year = $args->getOpt('year');
$day = $args->getOpt('day');
switch ($args->getCommand()) {
case 'run':
if (!empty($args->getOpt('day'))) {
$advent->runDay($year, $day);
} else {
$doneDays = 25;
for ($i = 1; $i <= $doneDays; $i++) {
$advent->runDay($year, $i);
}
}
break;
case 'test':
if (!empty($day)) {
$day = 'Day' . sprintf('%02d', $day);
echo "*** TESTING $year DAY $day ***" . PHP_EOL;
system("\"vendor/bin/phpunit\" --testdox AdventOfCode$year/$day/{$day}Test.php");
} else {
system("\"vendor/bin/phpunit\" --testdox AdventOfCode$year/.");
}
break;
}
}