Skip to content

Commit c5d9e1b

Browse files
committed
clean up cli help setup, allow single string, add command prefix in automatically
1 parent dd019f5 commit c5d9e1b

9 files changed

Lines changed: 35 additions & 28 deletions

File tree

cli/ob.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,18 @@ public function help()
8181
require_once(OB_LOCAL . '/core/cli/' . $cliPath);
8282

8383
$cliClass = new $cliClassName();
84-
$rows = [...$rows, ...$cliClass->help()];
84+
$help = $cliClass->help();
85+
86+
if (is_array($help)) {
87+
foreach ($help as &$helpItem) {
88+
$helpItem[0] = $cliCommand . ' ' . $helpItem[0];
89+
}
90+
$rows = [...$rows, ...$help];
91+
}
92+
93+
if (is_string($help)) {
94+
$rows = [...$rows, [$cliCommand, $help]];
95+
}
8596
}
8697

8798
echo Helpers::table(spacing: 5, rows: $rows);

core/base/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class CLI
1515
protected $db;
1616
protected $models;
1717

18-
protected array $help;
18+
protected array|string $help;
1919

2020
final public function __construct()
2121
{
@@ -27,7 +27,7 @@ final public function __construct()
2727
}
2828
}
2929

30-
final public function help(): array
30+
final public function help(): array|string
3131
{
3232
return $this->help;
3333
}

core/cli/CheckInstall.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
class CheckInstall extends CLI
88
{
9-
protected array $help = [
10-
['check install', 'check installation for errors']
11-
];
9+
protected array|string $help = 'check installation for errors';
1210

1311
public function run(array $args): bool
1412
{

core/cli/CheckMedia.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
class CheckMedia extends CLI
88
{
9-
protected array $help = [
10-
['check media', 'check media for errors'],
11-
];
9+
protected array|string $help = 'check media for errors';
1210

1311
public function run(array $args): bool
1412
{

core/cli/Cron.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
class Cron extends CLI
88
{
99
private string $obCronLog;
10-
protected array $help = [
11-
['cron run', 'run scheduled tasks once'],
12-
['cron run <module> <task> [now]', 'run scheduled task for module'],
13-
['cron monitor', 'monitor and run cron tasks as needed'],
10+
protected array|string $help = [
11+
['run', 'run scheduled tasks once'],
12+
['run <module> <task> [now]', 'run scheduled task for module'],
13+
['monitor', 'monitor and run cron tasks as needed'],
1414
];
1515

1616
public function run(array $args): bool

core/cli/Modules.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
class Modules extends CLI
88
{
9-
protected array $help = [
10-
['modules list', 'list all modules and their status'],
11-
['modules install <name>', 'install module'],
12-
['modules uninstall <name>', 'uninstall module'],
13-
['modules purge <name>', 'uninstall module and delete all data'],
9+
protected array|string $help = [
10+
['list', 'list all modules and their status'],
11+
['install <name>', 'install module'],
12+
['uninstall <name>', 'uninstall module'],
13+
['purge <name>', 'uninstall module and delete all data'],
1414
];
1515

1616
public function run(array $args): bool

core/cli/Passwd.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class Passwd extends CLI
88
{
9-
protected array $help = [
10-
['passwd <username>', 'change password for user'],
9+
protected array|string $help = [
10+
['<username>', 'change password for user'],
1111
];
1212

1313
public function run(array $args): bool

core/cli/UpdatesList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
class UpdatesList extends CLI
88
{
9-
protected array $help = [
10-
['updates list all', 'list all available updates'],
11-
['updates list core', 'list core ob updates'],
12-
['updates list module <name>', 'list updates for specified module'],
9+
protected array|string $help = [
10+
['all', 'list all available updates'],
11+
['core', 'list core ob updates'],
12+
['module <name>', 'list updates for specified module'],
1313
];
1414

1515
public function run(array $args): bool

core/cli/UpdatesRun.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
class UpdatesRun extends CLI
88
{
9-
protected array $help = [
10-
['updates run all', 'run all available updates'],
11-
['updates run core', 'run core ob updates'],
12-
['updates run module <name>', 'run updates for specified module'],
9+
protected array|string $help = [
10+
['all', 'run all available updates'],
11+
['core', 'run core ob updates'],
12+
['module <name>', 'run updates for specified module'],
1313
];
1414

1515
public function run(array $args): bool

0 commit comments

Comments
 (0)