1919use Symfony \Component \Console \Input \InputOption ;
2020use Symfony \Component \Console \Output \OutputInterface ;
2121
22- class ListDaemons extends Command
23- {
22+ class ListDaemons extends Command {
2423
2524 public function __construct (
2625 private readonly DaemonConfigService $ daemonConfigService ,
@@ -29,15 +28,13 @@ public function __construct(
2928 parent ::__construct ();
3029 }
3130
32- protected function configure (): void
33- {
31+ protected function configure (): void {
3432 $ this ->setName ('app_api:daemon:list ' );
3533 $ this ->setDescription ('List registered daemons ' );
3634 $ this ->addOption ('show-deploy-config ' , null , InputOption::VALUE_NONE , 'Show full deploy configuration ' );
3735 }
3836
39- protected function execute (InputInterface $ input , OutputInterface $ output ): int
40- {
37+ protected function execute (InputInterface $ input , OutputInterface $ output ): int {
4138 $ daemonConfigs = $ this ->daemonConfigService ->getRegisteredDaemonConfigs ();
4239 if (count ($ daemonConfigs ) === 0 ) {
4340 $ output ->writeln ('No registered daemon configs. ' );
@@ -47,53 +44,56 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4744 $ defaultDaemonName = $ this ->appConfig ->getValueString (Application::APP_ID , 'default_daemon_config ' , lazy: true );
4845
4946 $ output ->writeln ('Registered ExApp daemon configs: ' );
50- $ table = new Table ($ output );
5147
52- $ showDeployConfig = $ input ->getOption ('show-deploy-config ' );
48+ if ( $ input ->getOption ('show-deploy-config ' )) {
5349
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 = [];
61- foreach ($ daemonConfigs as $ daemon ) {
62- $ deployConfig = $ daemon ->getDeployConfig ();
63- $ newRow = [
64- $ daemon ->getName () === $ defaultDaemonName ? '* ' : '' ,
65- $ daemon ->getName (),
66- $ daemon ->getDisplayName (),
67- $ daemon ->getAcceptsDeployId (),
68- $ daemon ->getProtocol (),
69- $ daemon ->getHost (),
70- $ deployConfig ['nextcloud_url ' ],
71- isset ($ deployConfig ['harp ' ]) ? 'yes ' : 'no ' ,
72- $ deployConfig ['harp ' ]['frp_address ' ] ?? '(none) ' ,
73- $ deployConfig ['harp ' ]['docker_socket_port ' ] ?? '(none) ' ,
74- ];
75-
76- if ($ showDeployConfig ) {
77- $ deployConfigOutput = [
78- 'net ' => $ deployConfig ['net ' ],
79- 'nextcloud_url ' => $ deployConfig ['nextcloud_url ' ],
80- 'computeDevice ' => $ deployConfig ['computeDevice ' ],
81- ];
50+ foreach ($ daemonConfigs as $ daemon ) {
51+ $ deployConfig = $ daemon ->getDeployConfig ();
8252
83- if (isset ($ deployConfig ['harp ' ])) {
84- $ deployConfigOutput [ ' harp ' ] = $ deployConfig [ ' harp ' ];
53+ if (isset ($ deployConfig ['haproxy_password ' ])) {
54+ $ deployConfig [ ' haproxy_password ' ] = ' *** ' ;
8555 }
8656
87- array_push (
88- $ newRow ,
89- json_encode ($ deployConfigOutput , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES )
90- );
57+ $ daemonInfo = [
58+ $ daemon ->getName () === $ defaultDaemonName ? '* ' : '' ,
59+ $ daemon ->getName (),
60+ $ daemon ->getDisplayName (),
61+ $ daemon ->getAcceptsDeployId (),
62+ $ daemon ->getProtocol (),
63+ $ daemon ->getHost (),
64+ $ deployConfig ,
65+ ];
66+
67+ echo json_encode ($ daemonInfo , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
68+ $ output ->writeln ('' );
9169 }
92- array_push ($ rows , $ newRow );
93- }
9470
95- $ table ->setRows ($ rows );
96- $ table ->render ();
71+ } else {
72+
73+ $ table = new Table ($ output );
74+ $ headers = ['Def ' , 'Name ' , 'Display name ' , 'Deploy ID ' , 'Protocol ' , 'Host ' , 'NC Url ' , 'Is HaRP ' , 'HaRP FRP Address ' , 'HaRP Docker Socket Port ' ];
75+ $ table ->setHeaders ($ headers );
76+
77+ $ rows = [];
78+ foreach ($ daemonConfigs as $ daemon ) {
79+ $ deployConfig = $ daemon ->getDeployConfig ();
80+ $ rows [] = [
81+ $ daemon ->getName () === $ defaultDaemonName ? '* ' : '' ,
82+ $ daemon ->getName (),
83+ $ daemon ->getDisplayName (),
84+ $ daemon ->getAcceptsDeployId (),
85+ $ daemon ->getProtocol (),
86+ $ daemon ->getHost (),
87+ $ deployConfig ['nextcloud_url ' ],
88+ isset ($ deployConfig ['harp ' ]) ? 'yes ' : 'no ' ,
89+ $ deployConfig ['harp ' ]['frp_address ' ] ?? '(none) ' ,
90+ $ deployConfig ['harp ' ]['docker_socket_port ' ] ?? '(none) ' ,
91+ ];
92+ }
93+
94+ $ table ->setRows ($ rows );
95+ $ table ->render ();
96+ }
9797
9898 return 0 ;
9999 }
0 commit comments