99
1010namespace OCA \AppAPI \Command \Daemon ;
1111
12+ use OC \Core \Command \Base ;
1213use OCA \AppAPI \AppInfo \Application ;
1314use OCA \AppAPI \Service \DaemonConfigService ;
14-
1515use OCP \IAppConfig ;
16- use Symfony \Component \Console \Command \Command ;
1716use Symfony \Component \Console \Helper \Table ;
1817use Symfony \Component \Console \Input \InputInterface ;
1918use Symfony \Component \Console \Output \OutputInterface ;
2019
21- class ListDaemons extends Command {
20+ class ListDaemons extends Base {
2221
2322 public function __construct (
2423 private readonly DaemonConfigService $ daemonConfigService ,
@@ -28,6 +27,7 @@ public function __construct(
2827 }
2928
3029 protected function configure (): void {
30+ parent ::configure ();
3131 $ this ->setName ('app_api:daemon:list ' );
3232 $ this ->setDescription ('List registered daemons ' );
3333 }
@@ -41,27 +41,50 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4141
4242 $ defaultDaemonName = $ this ->appConfig ->getValueString (Application::APP_ID , 'default_daemon_config ' , lazy: true );
4343
44- $ output -> writeln ( ' Registered ExApp daemon configs: ' );
45- $ 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 = [] ;
44+ if ( in_array ( $ input -> getOption ( ' output ' ), [ self :: OUTPUT_FORMAT_JSON , self :: OUTPUT_FORMAT_JSON_PRETTY ], true )) {
45+ $ allDaemonInfo = [] ;
46+ foreach ( $ daemonConfigs as $ daemon ) {
47+ $ deployConfig = $ daemon -> getDeployConfig () ;
4848
49- foreach ($ daemonConfigs as $ daemon ) {
50- $ rows [] = [
51- $ daemon ->getName () === $ defaultDaemonName ? '* ' : '' ,
52- $ daemon ->getName (), $ daemon ->getDisplayName (),
53- $ daemon ->getAcceptsDeployId (),
54- $ daemon ->getProtocol (),
55- $ 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) ' ,
60- ];
61- }
49+ if (isset ($ deployConfig ['haproxy_password ' ])) {
50+ $ deployConfig ['haproxy_password ' ] = '*** ' ;
51+ }
52+
53+ $ allDaemonInfo [] = [
54+ 'name ' => $ daemon ->getName (),
55+ 'display_name ' => $ daemon ->getDisplayName (),
56+ 'deploy_id ' => $ daemon ->getAcceptsDeployId (),
57+ 'protocol ' => $ daemon ->getProtocol (),
58+ 'host ' => $ daemon ->getHost (),
59+ 'deploy_config ' => $ deployConfig ,
60+ ];
61+ }
62+ $ this ->writeArrayInOutputFormat ($ input , $ output , $ allDaemonInfo );
63+ } else {
64+ $ table = new Table ($ output );
65+ $ table ->setHeaders (['Def ' , 'Name ' , 'Display name ' , 'Deploy ID ' , 'Protocol ' , 'Host ' , 'NC Url ' , 'Is HaRP ' , 'HaRP FRP Address ' , 'HaRP Docker Socket Port ' ]);
6266
63- $ table ->setRows ($ rows );
64- $ table ->render ();
67+ $ rows = [];
68+ foreach ($ daemonConfigs as $ daemon ) {
69+ $ deployConfig = $ daemon ->getDeployConfig ();
70+ $ rows [] = [
71+ $ daemon ->getName () === $ defaultDaemonName ? '* ' : '' ,
72+ $ daemon ->getName (),
73+ $ daemon ->getDisplayName (),
74+ $ daemon ->getAcceptsDeployId (),
75+ $ daemon ->getProtocol (),
76+ $ daemon ->getHost (),
77+ $ deployConfig ['nextcloud_url ' ],
78+ isset ($ deployConfig ['harp ' ]) ? 'yes ' : 'no ' ,
79+ $ deployConfig ['harp ' ]['frp_address ' ] ?? '(none) ' ,
80+ $ deployConfig ['harp ' ]['docker_socket_port ' ] ?? '(none) ' ,
81+ ];
82+ }
83+
84+ $ table ->setRows ($ rows );
85+ $ output ->writeln ('Registered ExApp daemon configs: ' );
86+ $ table ->render ();
87+ }
6588
6689 return 0 ;
6790 }
0 commit comments