@@ -139,7 +139,7 @@ class DevChatWrapper {
139139
140140 val commandList: JSONArray
141141 get() {
142- val result = runRunCommand( " --list" , null )
142+ val result = runCommand( null , " run " , " --list" )
143143 return JSON .parseArray(result)
144144 }
145145 val commandNamesList: Array <String ?>
@@ -163,26 +163,17 @@ class DevChatWrapper {
163163 }
164164
165165 fun listTopics (): JSONArray {
166- val result = runTopicCommand( " --list" , null )
166+ val result = runCommand( null , " topic " , " --list" )
167167 return JSON .parseArray(result)
168168 }
169169
170- fun runRunCommand ( subCommand : String? , flags : Map <String , List <String ?>>? ): String {
170+ fun runCommand ( flags : Map <String , List <String ?>>? , vararg subCommands : String ): String {
171171 return try {
172- val commands: List <String ?> = prepareCommand(flags, " run " , subCommand !! )
172+ val commands: List <String ?> = prepareCommand(flags, * subCommands )
173173 execCommand(commands)
174174 } catch (e: Exception ) {
175175 Log .error(" Failed to run [run] command: " + e.message)
176- throw RuntimeException (" Failed to run [run] command" , e)
177- }
178- }
179-
180- fun runTopicCommand (subCommand : String? , flags : Map <String , List <String ?>>? ): String {
181- return try {
182- val commands: List <String ?> = prepareCommand(flags, " topic" , subCommand!! )
183- execCommand(commands)
184- } catch (e: Exception ) {
185- throw RuntimeException (" Failed to run [topic] command" , e)
176+ throw RuntimeException (" Failed to run [${subCommands} ] command" , e)
186177 }
187178 }
188179
@@ -205,7 +196,7 @@ class DevChatWrapper {
205196 private fun prepareCommand (subCommand : String , flags : Map <String , List <String ?>>, message : String? ): List <String ?> {
206197 val commands = prepareCommand(flags, subCommand)
207198 // Add the message to the command list
208- if (message != null && ! message.isEmpty ()) {
199+ if (! message.isNullOrEmpty ()) {
209200 commands.add(" --" )
210201 commands.add(message)
211202 }
0 commit comments