1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace clipr; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_clipr\Clipr\Useful; |
7
|
|
|
use kalanis\kw_clipr\CliprException; |
8
|
|
|
use kalanis\kw_clipr\Output\TPrettyTable; |
9
|
|
|
use kalanis\kw_clipr\Tasks\ATask; |
10
|
|
|
use kalanis\kw_clipr\Tasks\Params; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class Help extends ATask |
14
|
|
|
{ |
15
|
|
|
use TPrettyTable; |
16
|
|
|
|
17
|
2 |
|
public function desc(): string |
18
|
|
|
{ |
19
|
2 |
|
return 'Help with Clipr tasks'; |
20
|
|
|
} |
21
|
|
|
|
22
|
3 |
|
public function process(): int |
23
|
|
|
{ |
24
|
3 |
|
$this->writeLn('<yellow><bluebg>+======================+</bluebg></yellow>'); |
25
|
3 |
|
$this->writeLn('<yellow><bluebg>| kw_clipr |</bluebg></yellow>'); |
26
|
3 |
|
$this->writeLn('<yellow><bluebg>+======================+</bluebg></yellow>'); |
27
|
3 |
|
$this->writeLn('<yellow><bluebg>| Help with task |</bluebg></yellow>'); |
28
|
3 |
|
$this->writeLn('<yellow><bluebg>+======================+</bluebg></yellow>'); |
29
|
|
|
|
30
|
3 |
|
if (empty($this->loader)) { |
31
|
1 |
|
$this->sendErrorMessage('Need any loader to get tasks!'); |
32
|
1 |
|
return static::STATUS_LIB_ERROR; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
try { |
36
|
2 |
|
$taskName = Useful::getNthParam($this->inputs->getInArray(), 2) ?? static::class; |
37
|
2 |
|
$task = $this->loader->getTask($taskName); |
38
|
2 |
|
if (!$task) { |
39
|
1 |
|
throw new CliprException(sprintf('Unknown task *%s* - check name, interface or your config paths.', $taskName), static::STATUS_NO_TARGET_RESOURCE); |
40
|
|
|
} |
41
|
1 |
|
$task->initTask($this->translator, $this->inputs, $this->loader); |
42
|
1 |
|
$this->writeLn(); |
43
|
1 |
|
$this->writeLn('<lcyan>Command:</lcyan>'); |
44
|
1 |
|
$this->writeLn('<yellow>' . Useful::getTaskCall($task) . '</yellow>'); |
45
|
1 |
|
$this->writeLn('<lcyan>Description:</lcyan>'); |
46
|
1 |
|
$this->writeLn($task->desc()); |
47
|
1 |
|
$this->writeLn('<lcyan>Available params:</lcyan>'); |
48
|
|
|
|
49
|
1 |
|
$this->setTableHeaders(['Variable', 'Cli key', 'Short key', 'Current value', 'Description']); |
50
|
1 |
|
foreach ($task->getParams()->getAvailableOptions() as $param) { |
51
|
|
|
/** @var Params\Option $param */ |
52
|
1 |
|
$this->setTableDataLine([$param->getVariable(), $param->getCliKey(), (string) $param->getShort(), (string) $param->getValue(), $param->getDescription()]); |
53
|
|
|
} |
54
|
1 |
|
$this->dumpTable(); |
55
|
|
|
|
56
|
1 |
|
} catch (CliprException $ex) { |
57
|
1 |
|
$this->writeLn($ex->getMessage()); |
58
|
1 |
|
return $ex->getCode(); |
59
|
|
|
} |
60
|
1 |
|
return static::STATUS_SUCCESS; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|