Skip to content

Commit cf615a6

Browse files
committed
feat(daemon): add --show-deploy-config flag to daemon:list command
1 parent a9d099f commit cf615a6

1 file changed

Lines changed: 44 additions & 12 deletions

File tree

lib/Command/Daemon/ListDaemons.php

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Helper\Table;
1818
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Input\InputOption;
1920
use Symfony\Component\Console\Output\OutputInterface;
2021

21-
class ListDaemons extends Command {
22+
class ListDaemons extends Command
23+
{
2224

2325
public function __construct(
2426
private readonly DaemonConfigService $daemonConfigService,
25-
private readonly IAppConfig $appConfig
27+
private readonly IAppConfig $appConfig
2628
) {
2729
parent::__construct();
2830
}
2931

30-
protected function configure(): void {
32+
protected function configure(): void
33+
{
3134
$this->setName('app_api:daemon:list');
3235
$this->setDescription('List registered daemons');
36+
$this->addOption('show-deploy-config', null, InputOption::VALUE_NONE, 'Show full deploy configuration');
3337
}
3438

35-
protected function execute(InputInterface $input, OutputInterface $output): int {
39+
protected function execute(InputInterface $input, OutputInterface $output): int
40+
{
3641
$daemonConfigs = $this->daemonConfigService->getRegisteredDaemonConfigs();
3742
if (count($daemonConfigs) === 0) {
3843
$output->writeln('No registered daemon configs.');
@@ -43,21 +48,48 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4348

4449
$output->writeln('Registered ExApp daemon configs:');
4550
$table = new Table($output);
46-
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP', 'HaRP FRP Address', 'HaRP Docker Socket Port']);
47-
$rows = [];
4851

52+
$showDeployConfig = $input->getOption('show-deploy-config');
53+
54+
$headers = ['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP', 'HaRP FRP Address', 'HaRP Docker Socket Port'];
55+
if ($showDeployConfig) {
56+
$headers[] = 'Deploy Config JSON';
57+
}
58+
$table->setHeaders($headers);
59+
60+
$rows = [];
4961
foreach ($daemonConfigs as $daemon) {
50-
$rows[] = [
62+
$deployConfig = $daemon->getDeployConfig();
63+
$newRow = [
5164
$daemon->getName() === $defaultDaemonName ? '*' : '',
52-
$daemon->getName(), $daemon->getDisplayName(),
65+
$daemon->getName(),
66+
$daemon->getDisplayName(),
5367
$daemon->getAcceptsDeployId(),
5468
$daemon->getProtocol(),
5569
$daemon->getHost(),
56-
$daemon->getDeployConfig()['nextcloud_url'],
57-
isset($daemon->getDeployConfig()['harp']) ? 'yes' : 'no',
58-
$daemon->getDeployConfig()['harp']['frp_address'] ?? '(none)',
59-
$daemon->getDeployConfig()['harp']['docker_socket_port'] ?? '(none)',
70+
$deployConfig['nextcloud_url'],
71+
isset($deployConfig['harp']) ? 'yes' : 'no',
72+
$deployConfig['harp']['frp_address'] ?? '(none)',
73+
$deployConfig['harp']['docker_socket_port'] ?? '(none)',
6074
];
75+
76+
if ($showDeployConfig) {
77+
$deployConfigOutput = [
78+
'net' => $deployConfig['net'],
79+
'nextcloud_url' => $deployConfig['nextcloud_url'],
80+
'computeDevice' => $deployConfig['computeDevice'],
81+
];
82+
83+
if (isset($deployConfig['harp'])) {
84+
$deployConfigOutput['harp'] = $deployConfig['harp'];
85+
}
86+
87+
array_push(
88+
$newRow,
89+
json_encode($deployConfigOutput, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
90+
);
91+
}
92+
array_push($rows, $newRow);
6193
}
6294

6395
$table->setRows($rows);

0 commit comments

Comments
 (0)