@@ -68,7 +68,7 @@ static struct command_result *reckless_result(struct io_conn *conn,
6868 reckless -> process_failed );
6969 return command_finished (reckless -> cmd , response );
7070 }
71- const jsmntok_t * results , * result , * logs , * log ;
71+ const jsmntok_t * results , * result , * logs , * log , * conf ;
7272 size_t i ;
7373 jsmn_parser parser ;
7474 jsmntok_t * toks ;
@@ -97,15 +97,26 @@ static struct command_result *reckless_result(struct io_conn *conn,
9797 }
9898
9999 response = jsonrpc_stream_success (reckless -> cmd );
100- json_array_start (response , "result" );
101100 results = json_get_member (reckless -> stdoutbuf , toks , "result" );
102- json_for_each_arr (i , result , results ) {
103- json_add_string (response ,
104- NULL ,
105- json_strdup (reckless , reckless -> stdoutbuf ,
106- result ));
101+ conf = json_get_member (reckless -> stdoutbuf , results , "requested_lightning_conf" );
102+ if (conf ) {
103+ plugin_log (plugin , LOG_DBG , "dealing with listconfigs output" );
104+ json_object_start (response , "result" );
105+ json_for_each_obj (i , result , results ) {
106+ json_add_tok (response , json_strdup (tmpctx , reckless -> stdoutbuf , result ), result + 1 , reckless -> stdoutbuf );
107+ }
108+ json_object_end (response );
109+
110+ } else {
111+ json_array_start (response , "result" );
112+ json_for_each_arr (i , result , results ) {
113+ json_add_string (response ,
114+ NULL ,
115+ json_strdup (reckless , reckless -> stdoutbuf ,
116+ result ));
117+ }
118+ json_array_end (response );
107119 }
108- json_array_end (response );
109120 json_array_start (response , "log" );
110121 logs = json_get_member (reckless -> stdoutbuf , toks , "log" );
111122 json_for_each_arr (i , log , logs ) {
@@ -211,13 +222,25 @@ static struct io_plan *stderr_conn_init(struct io_conn *conn,
211222 return stderr_read_more (conn , reckless );
212223}
213224
225+ static bool is_single_arg_cmd (const char * command ) {
226+ if (strcmp (command , "listconfig" ))
227+ return true;
228+ if (strcmp (command , "listavailable" ))
229+ return true;
230+ if (strcmp (command , "listinstalled" ))
231+ return true;
232+ return false;
233+ }
234+
214235static struct command_result * reckless_call (struct command * cmd ,
215236 const char * subcommand ,
216237 const char * target ,
217238 const char * target2 )
218239{
219- if (!subcommand || !target )
220- return command_fail (cmd , PLUGIN_ERROR , "invalid reckless call" );
240+ if (!is_single_arg_cmd (subcommand )) {
241+ if (!subcommand || !target )
242+ return command_fail (cmd , PLUGIN_ERROR , "invalid reckless call" );
243+ }
221244 char * * my_call ;
222245 my_call = tal_arrz (tmpctx , char * , 0 );
223246 tal_arr_expand (& my_call , "reckless" );
@@ -273,7 +296,7 @@ static struct command_result *json_reckless(struct command *cmd,
273296 /* Allow check command to evaluate. */
274297 if (!param (cmd , buf , params ,
275298 p_req ("command" , param_string , & command ),
276- p_req ("target/subcommand" , param_string , & target ),
299+ p_opt ("target/subcommand" , param_string , & target ),
277300 p_opt ("target" , param_string , & target2 ),
278301 NULL ))
279302 return command_param_failed ();
0 commit comments