use of jline.FileNameCompletor in project GNS by MobilityFirst.
the class ConsoleModule method loadCompletor.
/**
* Loads the commands for this module
*/
protected void loadCompletor() {
List<Completor> completors = new LinkedList<>();
int size = commands.size();
if (size > 0) {
TreeSet<String> set = new TreeSet<>();
Iterator<ConsoleCommand> it = commands.iterator();
while (it.hasNext()) {
set.add(it.next().getCommandName());
}
completors.add(new SimpleCompletor(set.toArray(new String[size])));
}
completors.add(new FileNameCompletor());
Completor[] completorsArray = completors.toArray(new Completor[completors.size()]);
consoleCompletor = new ArgumentCompletor(completorsArray, new CommandDelimiter());
}
use of jline.FileNameCompletor in project tomee by apache.
the class CliRunnable method run.
@Override
public void run() {
clean();
try {
final StreamManager streamManager = new StreamManager(out, err, lineSep);
final ConsoleReader reader = new ConsoleReader(sin, streamManager.getSout());
reader.addCompletor(new FileNameCompletor());
reader.addCompletor(new SimpleCompletor(COMMANDS.keySet().toArray(new String[COMMANDS.size()])));
// TODO : add completers
String line;
final StringBuilder builtWelcome = new StringBuilder("Apache OpenEJB ").append(OpenEjbVersion.get().getVersion()).append(" build: ").append(OpenEjbVersion.get().getDate()).append("-").append(OpenEjbVersion.get().getTime()).append(lineSep);
if (tomee) {
builtWelcome.append(OS_LINE_SEP).append(PROPERTIES.getProperty(WELCOME_TOMEE_KEY));
} else {
builtWelcome.append(OS_LINE_SEP).append(PROPERTIES.getProperty(WELCOME_OPENEJB_KEY));
}
builtWelcome.append(lineSep).append(PROPERTIES.getProperty(WELCOME_COMMON_KEY));
streamManager.writeOut(OpenEjbVersion.get().getUrl());
streamManager.writeOut(builtWelcome.toString().replace("$bind", bind).replace("$port", Integer.toString(port)).replace("$name", NAME).replace(OS_LINE_SEP, lineSep));
while ((line = reader.readLine(prompt())) != null) {
// do we need a command for it?
if (EXIT_COMMAND.equals(line)) {
break;
}
Class<?> cmdClass = null;
String key = null;
for (final Map.Entry<String, Class<?>> cmd : COMMANDS.entrySet()) {
if (line.startsWith(cmd.getKey())) {
cmdClass = cmd.getValue();
key = cmd.getKey();
break;
}
}
if (cmdClass != null) {
final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
recipe.setProperty("streamManager", streamManager);
recipe.setProperty("command", line);
recipe.setProperty("scripter", scripter);
recipe.setProperty("commands", COMMANDS);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.NAMED_PARAMETERS);
try {
final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
cmdInstance.execute(trunc(line, key));
} catch (Exception e) {
streamManager.writeErr(e);
}
} else {
streamManager.writeErr("sorry i don't understand '" + line + "'");
}
}
clean();
} catch (IOException e) {
clean();
throw new CliRuntimeException(e);
}
}
use of jline.FileNameCompletor in project tomee by apache.
the class Client method main.
public static void main(final String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Pass the base url as parameter");
return;
}
final ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
reader.addCompletor(new FileNameCompletor());
reader.addCompletor(new SimpleCompletor(CommandManager.keys().toArray(new String[CommandManager.size()])));
String line;
while ((line = reader.readLine(PROMPT)) != null) {
if (EXIT_CMD.equals(line)) {
break;
}
Class<?> cmdClass = null;
for (Map.Entry<String, Class<?>> cmd : CommandManager.getCommands().entrySet()) {
if (line.startsWith(cmd.getKey())) {
cmdClass = cmd.getValue();
break;
}
}
if (cmdClass != null) {
final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
recipe.setProperty("url", args[0]);
recipe.setProperty("command", line);
recipe.setProperty("commands", CommandManager.getCommands());
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.NAMED_PARAMETERS);
try {
final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
cmdInstance.execute(line);
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.err.println("sorry i don't understand '" + line + "'");
}
}
}
Aggregations