Skip to content

Commit cf95e73

Browse files
Merge branch 'pullrequests/ovenum/feature/license-command'
2 parents 4567eb1 + cacbd6e commit cf95e73

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ This should print the Kirby CLI version and a list of available commands
4949
- kirby install
5050
- kirby install:kit
5151
- kirby install:repo
52+
- kirby license:info
53+
- kirby license:renewal
5254
- kirby make:blueprint
5355
- kirby make:collection
5456
- kirby make:command

commands/license/info.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
use Kirby\CLI\CLI;
6+
7+
return [
8+
'description' => 'Displays Kirby license information in table or JSON format.',
9+
'args' => [
10+
'format' => [
11+
'description' => 'Output format: table or json.',
12+
'prefix' => 'f',
13+
'longPrefix' => 'format'
14+
]
15+
],
16+
'command' => static function (CLI $cli): void {
17+
$kirby = $cli->kirby();
18+
19+
$supportedFormats = [
20+
'table',
21+
'json'
22+
];
23+
24+
$licenseFields = [
25+
'activation',
26+
'code',
27+
'date',
28+
'domain',
29+
'email'
30+
];
31+
32+
$format = $cli->arg('format');
33+
$format = $format ? $format : 'table';
34+
35+
if (in_array($format, $supportedFormats) === false) {
36+
$cli->error('Invalid format. Supported formats are: ' . implode(', ', $supportedFormats));
37+
return;
38+
}
39+
40+
$license = $kirby->system()->license();
41+
$data = $license->content();
42+
43+
// Only include the fields we want to display
44+
$data = array_intersect_key($data, array_flip($licenseFields));
45+
$data['renewal'] = $license->renewal(format: 'Y-m-d H:i:s', handler: 'date');
46+
47+
// Print License info as table
48+
if ($format === 'table') {
49+
$cli->success('Kirby License Information:');
50+
$tableData = [];
51+
foreach ($data as $key => $value) {
52+
$tableData[] = ['Key' => $key, 'Value' => $value ?? ''];
53+
}
54+
55+
// Use the Climate library to create a table for better readability
56+
$cli->climate()->table($tableData);
57+
} else {
58+
// Print License info as JSON
59+
$cli->climate()->json($data);
60+
}
61+
}
62+
];

commands/license/renewal.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
use Kirby\CLI\CLI;
6+
7+
return [
8+
'description' => 'Show the renewal date of the activated Kirby license.',
9+
'args' => [
10+
'format' => [
11+
'prefix' => 'f',
12+
'longPrefix' => 'format',
13+
'description' => 'The format for the renewal date (any format supported by PHP\'s `date()` function) or "timestamp"',
14+
'defaultValue' => 'Y-m-d'
15+
]
16+
],
17+
'command' => static function (CLI $cli): void {
18+
$kirby = $cli->kirby();
19+
20+
$license = $kirby->system()->license();
21+
$format = $cli->arg('format');
22+
23+
if (strtolower($format) === 'timestamp') {
24+
$format = null;
25+
}
26+
27+
$renewal = $license->renewal(
28+
format: $format,
29+
handler: 'date'
30+
);
31+
32+
if ($renewal === null) {
33+
$cli->error('No Kirby License is activated.');
34+
return;
35+
}
36+
37+
$cli->success($renewal);
38+
}
39+
];

0 commit comments

Comments
 (0)