1212import java .lang .reflect .Method ;
1313import java .util .Arrays ;
1414import java .util .concurrent .ScheduledExecutorService ;
15- public record InputRunnable (LineReader lineReader , LogWriter logWriter , CommandHandler commandHandler , ScheduledExecutorService scheduledExecutorService , String prompt , String commandNotAvailable , String commandArgumentNotAvailable ) implements Runnable {
15+
16+ public record InputRunnable (
17+ LineReader lineReader ,
18+ LogWriter logWriter ,
19+ CommandHandler commandHandler ,
20+ ScheduledExecutorService scheduledExecutorService ,
21+ String prompt ,
22+ String commandNotAvailable ,
23+ String commandArgumentNotAvailable ,
24+ String [] commandNotAvailableFormat ,
25+ String [] commandArgumentNotAvailableFormat )
26+ implements Runnable {
1627
1728 @ Override
1829 public void run () {
@@ -25,35 +36,49 @@ public void run() {
2536 final String [] strings = message .split (" " );
2637 final String command = strings [0 ];
2738 if (!command .isEmpty ()) {
28- if (this .commandHandler .getCommands ().containsKey (command )){
39+ if (this .commandHandler .getCommands ().containsKey (command )) {
2940 final String [] stringsToArray = Arrays .copyOfRange (strings , 1 , strings .length );
3041 if (stringsToArray .length > 0 ) {
3142 try {
3243 final Class <?> obj = this .commandHandler .getCommands ().get (command ).getClass ();
3344 final Method method = obj .getMethod ("onCommand" , String [].class );
3445 method .invoke (obj .newInstance (), (Object ) stringsToArray );
3546 } catch (final InvocationTargetException
36- | InstantiationException
37- | NoSuchMethodException
38- | IllegalAccessException exception ) {
47+ | InstantiationException
48+ | NoSuchMethodException
49+ | IllegalAccessException exception ) {
3950 throw new ConsoleLineException (
40- "instance creation error - parameter or object error" , exception );
51+ "instance creation error - parameter or object error" , exception );
4152 }
4253 } else {
43- if (this .commandArgumentNotAvailable () != null ) {
44- System .out .println (this .commandArgumentNotAvailable ());
54+
55+ if (this .commandArgumentNotAvailableFormat () != null ) {
56+ String [] formatData = this .commandArgumentNotAvailableFormat ();
57+ Object [] args = Arrays .copyOfRange (formatData , 1 , formatData .length );
58+ System .out .println (String .format (formatData [0 ], args ));
59+ } else {
60+ if (this .commandArgumentNotAvailable () != null ) {
61+ System .out .println (this .commandArgumentNotAvailable ());
62+ }
4563 }
4664 }
4765 } else {
48- if (this .commandNotAvailable () != null ){
49- System .out .println (this .commandNotAvailable ());
66+
67+ if (this .commandNotAvailableFormat () != null ) {
68+ String [] formatData = this .commandNotAvailableFormat ();
69+ Object [] args = Arrays .copyOfRange (formatData , 1 , formatData .length );
70+ System .out .println (String .format (formatData [0 ], args ));
71+ } else {
72+ if (this .commandNotAvailable () != null ) {
73+ System .out .println (this .commandNotAvailable ());
74+ }
5075 }
5176 }
52- }
5377 }
54- } catch (final UserInterruptException ignored ) {
78+ }
79+ } catch (final UserInterruptException ignored ) {
5580 Runtime .getRuntime ().exit (0 );
5681 } catch (final EndOfFileException ignored ) {
5782 }
58- }
5983 }
84+ }
0 commit comments