передача параметров в команду
This commit is contained in:
@@ -31,15 +31,18 @@ public class Main {
|
||||
|
||||
final ParsedLine parsedLine = reader.getParser().parse(line, 0);
|
||||
final String commandName = parsedLine.word();
|
||||
final String[] argv = parsedLine.words().subList(1, parsedLine.words().size()).toArray(new String[0]);
|
||||
|
||||
if (commandService.hasCommand(commandName)) {
|
||||
commandService.execute(session, commandName);
|
||||
commandService.execute(session, commandName, argv);
|
||||
}
|
||||
|
||||
terminalWriter.println("line = " + String.join(", ", parsedLine.words()));
|
||||
}
|
||||
} catch (UserInterruptException ignore) {
|
||||
// ignore
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ public interface CommandService extends CommandRegistry {
|
||||
|
||||
void register(String commandName, Command command);
|
||||
|
||||
void execute(CommandSession session, String commandName);
|
||||
Object execute(CommandSession session, String commandName);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,14 @@ public class CommandServiceImpl implements CommandService {
|
||||
));
|
||||
}
|
||||
|
||||
public void execute(CommandSession session, String commandName) {
|
||||
commands.get(commandName).execute().accept(new Builtins.CommandInput(commandName, new Object[0], session));
|
||||
public Object execute(CommandSession session, String command) {
|
||||
return execute(session, command, new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(CommandSession session, String command, String[] args) {
|
||||
commands.get(command).execute().accept(new Builtins.CommandInput(command, args, session));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package mc.server.shell;
|
||||
|
||||
import org.jline.builtins.Builtins;
|
||||
import org.jline.builtins.Builtins.CommandInput;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class SystemPropertiesCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void execute(Builtins.CommandInput commandInput) {
|
||||
final PrintWriter writer = commandInput.terminal().writer();
|
||||
public void execute(CommandInput input) {
|
||||
final PrintWriter writer = input.terminal().writer();
|
||||
|
||||
final String[] args = input.args();
|
||||
writer.printf("args = [%s]\n", String.join(", ", args));
|
||||
|
||||
System.getProperties().forEach((key, value) ->
|
||||
writer.println(String.format("%s = %s", key, value.toString())));
|
||||
writer.printf("%s = %s\n", key, value.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user