Skip to content

Commit 8975d52

Browse files
committed
Add new Format - to use our format schema
1 parent c04e896 commit 8975d52

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'de.mint.consoleline'
8-
version '1.0.7-1'
8+
version '1.0.8'
99

1010
java {
1111
toolchain {

src/main/java/de/mint/consoleline/event/input/InputRunnable.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
import java.lang.reflect.Method;
1313
import java.util.Arrays;
1414
import 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+
}

src/main/java/de/mint/consoleline/service/JlineExecutor.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class JlineExecutor {
4949

5050
private String prompt;
5151

52+
private String[] commandArgumentNotAvailableFormat;
53+
private String[] commandNotAvailableFormat;
54+
5255
private String prefix = null;
5356

5457
private boolean withCommandSystem = true;
@@ -186,7 +189,23 @@ public boolean isJna() {
186189
return this.jna;
187190
}
188191

189-
/**
192+
public String[] getCommandArgumentNotAvailableFormat() {
193+
return this.commandArgumentNotAvailableFormat;
194+
}
195+
196+
void setCommandArgumentNotAvailableFormat(String[] commandArgumentNotAvailableFormat) {
197+
this.commandArgumentNotAvailableFormat = commandArgumentNotAvailableFormat;
198+
}
199+
200+
public String[] getCommandNotAvailableFormat() {
201+
return commandNotAvailableFormat;
202+
}
203+
204+
public void setCommandNotAvailableFormat(String[] commandNotAvailableFormat) {
205+
this.commandNotAvailableFormat = commandNotAvailableFormat;
206+
}
207+
208+
/**
190209
* This function sets the value of the jna variable to the value of the jna parameter.
191210
*
192211
* @param jna If true, the JNA library will be used to access the native library. If false, the
@@ -453,7 +472,7 @@ private void createInputStream() {
453472
this.scheduledExecutorService,
454473
this.prompt,
455474
this.commandNotAvailable,
456-
this.commandArgumentNotAvailable);
475+
this.commandArgumentNotAvailable, this.commandNotAvailableFormat, this.commandArgumentNotAvailableFormat);
457476
this.createInputRunnable();
458477
}
459478
}

0 commit comments

Comments
 (0)