1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* See class comment |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @category Netresearch |
8
|
|
|
* @package Netresearch\Kite\Console\Command |
9
|
|
|
* @author Christian Opitz <[email protected]> |
10
|
|
|
* @license http://www.netresearch.de Netresearch Copyright |
11
|
|
|
* @link http://www.netresearch.de |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Netresearch\Kite\Console\Command; |
15
|
|
|
use Netresearch\Kite\Exception; |
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class LogCommand |
24
|
|
|
* |
25
|
|
|
* @category Netresearch |
26
|
|
|
* @package Netresearch\Kite\Console\Command |
27
|
|
|
* @author Christian Opitz <[email protected]> |
28
|
|
|
* @license http://www.netresearch.de Netresearch Copyright |
29
|
|
|
* @link http://www.netresearch.de |
30
|
|
|
*/ |
31
|
|
|
class LogCommand extends Command |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Configure the command |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
protected function configure() |
39
|
|
|
{ |
40
|
|
|
$this |
41
|
|
|
->setName('log') |
42
|
|
|
->setDescription('Show the debug log of a previous kite job execution') |
43
|
|
|
->setDefinition( |
44
|
|
|
array( |
45
|
|
|
new InputOption('list', 'l', null, 'List available log entries'), |
46
|
|
|
new InputArgument('entry', null, 'The log entry - either full name, as in <info>--list</info> or last nth in the form <comment>^n</comment>') |
47
|
|
|
) |
48
|
|
|
); |
49
|
|
|
; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Executes the current command. |
54
|
|
|
* |
55
|
|
|
* This method is not abstract because you can use this class |
56
|
|
|
* as a concrete class. In this case, instead of defining the |
57
|
|
|
* execute() method, you set the code to execute by passing |
58
|
|
|
* a Closure to the setCode() method. |
59
|
|
|
* |
60
|
|
|
* @param InputInterface $input An InputInterface instance |
61
|
|
|
* @param OutputInterface $output An OutputInterface instance |
62
|
|
|
* |
63
|
|
|
* @return null|int null or 0 if everything went fine, or an error code |
64
|
|
|
* |
65
|
|
|
* @throws \LogicException When this abstract method is not implemented |
66
|
|
|
* |
67
|
|
|
* @see setCode() |
68
|
|
|
*/ |
69
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
70
|
|
|
{ |
71
|
|
|
$dir = $input->getOption('debug-dir'); |
72
|
|
|
if (!is_dir($dir)) { |
73
|
|
|
throw new Exception("Debug dir $dir doesn't exist"); |
74
|
|
|
} |
75
|
|
|
$files = glob($dir . '/*'); |
76
|
|
|
if ($input->getOption('list')) { |
77
|
|
|
foreach ($files as $file) { |
78
|
|
|
$output->writeln(basename($file)); |
79
|
|
|
} |
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
if ($entry = $input->getArgument('entry')) { |
83
|
|
|
if ($entry[0] === '^') { |
84
|
|
|
$back = ((int) substr($entry, 1)) + 1; |
85
|
|
|
while ($back--) { |
86
|
|
|
$show = array_pop($files); |
87
|
|
|
} |
88
|
|
|
} else { |
89
|
|
|
foreach ($files as $file) { |
90
|
|
|
if (basename($file) === $entry) { |
91
|
|
|
$show = $file; |
92
|
|
|
break; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} else { |
97
|
|
|
$show = array_pop($files); |
98
|
|
|
} |
99
|
|
|
if (!isset($show)) { |
100
|
|
|
throw new Exception("Couldn't find suitable entry"); |
101
|
|
|
} |
102
|
|
|
$output->write(file_get_contents($show), false, OutputInterface::OUTPUT_RAW); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
?> |
107
|
|
|
|