1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ReliqArts\Docweaver\Console\Commands; |
6
|
|
|
|
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use Illuminate\Console\Command; |
9
|
|
|
use ReliqArts\Docweaver\Contracts\Documentation\Publisher; |
10
|
|
|
use ReliqArts\Docweaver\Exceptions\InvalidDirectory; |
11
|
|
|
|
12
|
|
|
class Publish extends Command |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The name and signature of the console command. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature = 'docweaver:publish |
20
|
|
|
{product? : Product name} |
21
|
|
|
{source? : Product repository} |
22
|
|
|
{--y|y : Whether to skip confirmation} |
23
|
|
|
'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The console command description. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Publish documentation for product'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Publisher |
34
|
|
|
*/ |
35
|
|
|
protected $publisher; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create a new command instance. |
39
|
|
|
* |
40
|
|
|
* @param Publisher $publisher |
41
|
|
|
*/ |
42
|
|
|
public function __construct(Publisher $publisher) |
43
|
|
|
{ |
44
|
|
|
parent::__construct(); |
45
|
|
|
|
46
|
|
|
$this->publisher = $publisher; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Execute the console command. |
51
|
|
|
* |
52
|
|
|
* @throws InvalidDirectory |
53
|
|
|
*/ |
54
|
|
|
public function handle(): void |
55
|
|
|
{ |
56
|
|
|
$productName = $this->argument('product'); |
57
|
|
|
$productSource = $this->argument('source'); |
58
|
|
|
$skipConfirmation = $this->option('y'); |
59
|
|
|
$confirmationMessage = sprintf( |
60
|
|
|
"This command will attempt to pull documentation for product (%s) from %s}. \n" |
61
|
|
|
. 'Please ensure your internet connection is stable. Ready?', |
62
|
|
|
$productName, |
63
|
|
|
$productSource |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->comment(PHP_EOL |
67
|
|
|
. "<info>♣♣♣</info> Docweaver DocumentationPublisher \n" |
68
|
|
|
. 'Help is here, try: php artisan docweaver:publish --help'); |
69
|
|
|
|
70
|
|
View Code Duplication |
if ($skipConfirmation || $this->confirm($confirmationMessage)) { |
|
|
|
|
71
|
|
|
$this->info("Publishing {$productName}.\nT: " . Carbon::now()->toCookieString() . "\n----------"); |
72
|
|
|
|
73
|
|
|
$result = $this->publisher->publish($productName, $productSource, $this); |
|
|
|
|
74
|
|
|
|
75
|
|
|
if ($result->isSuccess()) { |
76
|
|
|
$this->info(PHP_EOL . '----------'); |
77
|
|
|
$this->comment("<info>✔</info> Done. {$result->getMessage()}"); |
78
|
|
|
|
79
|
|
|
// Display results |
80
|
|
|
$this->line(''); |
81
|
|
|
$headers = ['Time', 'Versions', 'Published', 'Updated']; |
82
|
|
|
$data = $result->getData(); |
83
|
|
|
$rows = [[ |
84
|
|
|
$data->executionTime, |
85
|
|
|
count($data->versions), |
86
|
|
|
count($data->versionsPublished), |
87
|
|
|
count($data->versionsUpdated), |
88
|
|
|
]]; |
89
|
|
|
$this->table($headers, $rows); |
90
|
|
|
$this->line(PHP_EOL); |
91
|
|
|
} else { |
92
|
|
|
$this->line(PHP_EOL . "<error>✘</error> {$result->getError()}"); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.