List<Completer> completors = new LinkedList<>(); // Completes using the filesystem completors.add(new FileNameCompleter()); // Completes using random words completors.add(new StringsCompleter("--arg0", "--arg1", "command")); // Aggregate the above completors AggregateCompleter aggComp = new AggregateCompleter(completors); // Parse the buffer line and complete each token ArgumentCompleter argComp = new ArgumentCompleter(aggComp); // Don't require all completors to match argComp.setStrict(false); // Add it all together conReader.addCompleter(argComp);
private List<Completer> selectCompleters() { final List<Completer> selection = new ArrayList<Completer>(); for (Command eachCommand: configuration.getCommands()) { selection.add(new StringsCompleter(eachCommand.getSyntax())); } selection.add(new FileNameCompleter()); return selection; }
void initAutoCompletion() { LinkedList<Completer> completors = new LinkedList<Completer>(); completors.add(new StringsCompleter(cmdMap.keySet())); completors.add(new StringsCompleter(fieldNames())); completors.add(new FileNameCompleter()); consoleReader.addCompleter(new ArgumentCompleter(completors)); } Collection<String> fieldNames() {
public Deploy() { super(); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Deploy and start a JBI artifact"); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); final FileNameCompleter c = new FileNameCompleter(); this.completers.put(BULK_SHORT_OPTION, c); this.completers.put(URL_SHORT_OPTION, c); this.completers.put(PROPERTIES_FILE_SHORT_OPTION, c); }
public Show() { super(); this.clParser = new DefaultParser(); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Print informations about a JBI artifact"); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); this.completers.put(URL_SHORT_OPTION, new FileNameCompleter()); this.completers.put(TYPE_SHORT_OPTION, ARTIFACT_TYPE_COMPLETER); }
private void initConsoleReader() { try { this.consoleReader = new ConsoleReader("IzPack", new FileInputStream(FileDescriptor.in), System.out, null); this.consoleReader.setHandleUserInterrupt(true); Terminal terminal = consoleReader.getTerminal(); if (terminal == null || terminal instanceof UnsupportedTerminal) { consoleReader.shutdown(); throw new Throwable("Terminal not initialized"); } fileNameCompleter = new FileNameCompleter(); } catch (Throwable t) { logger.log(Level.WARNING, "Cannot initialize the console reader. Falling back to default console.", t); } }
public StartArtifact() { super("start-artifact"); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Start a JBI artifact"); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); this.completers.put(URL_SHORT_OPTION, new FileNameCompleter()); this.completers.put(TYPE_SHORT_OPTION, ARTIFACT_TYPE_COMPLETER); }
public Undeploy() throws CommandException { super(); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Stop and uninstall or undeploy JBI artifacts"); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); this.completers.put(URL_SHORT_OPTION, new FileNameCompleter()); this.completers.put(TYPE_SHORT_OPTION, ARTIFACT_TYPE_COMPLETER); }
public StopArtifact() { super("stop-artifact"); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Stop a JBI artifact"); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); this.completers.put(URL_SHORT_OPTION, new FileNameCompleter()); this.completers.put(TYPE_SHORT_OPTION, ARTIFACT_TYPE_COMPLETER); }
private Completer getCommandCompleter() { List<Completer> customCompletor = new ArrayList<Completer>(); Set<String> candidateStrings = new HashSet<String>(); try { for (String key : CommandParserUtils.getAllCommandKewWords()) { candidateStrings.add(key.toUpperCase()); candidateStrings.add(key.toLowerCase()); } } catch (AssertionError e) { return null; } if (!candidateStrings.isEmpty()) { // odps key word completer, use default whitespace for arg delimiter ArgumentCompleter keyCompleter = new ArgumentCompleter(new StringsCompleter(candidateStrings)); keyCompleter.setStrict(false); customCompletor.add(keyCompleter); } // file patch completer, use default whitespace for arg delimiter ArgumentCompleter pathCompleter = new ArgumentCompleter(new FileNameCompleter()); pathCompleter.setStrict(false); customCompletor.add(pathCompleter); // aggregate two argument comepletor AggregateCompleter aggregateCompleter = new AggregateCompleter(customCompletor); return aggregateCompleter; }
public CommandCompleter(ConsoleReader consoleReader, ArgumentDelimiter argumentDelimiter, Iterable<Command> commands) { this.console = consoleReader; List<String> names = new ArrayList<>(); for (Command command : commands) { this.commands.add(command); names.add(command.getName()); List<String> options = new ArrayList<>(); for (OptionHelp optionHelp : command.getOptionsHelp()) { options.addAll(optionHelp.getOptions()); } AggregateCompleter argumentCompleters = new AggregateCompleter( new StringsCompleter(options), new FileNameCompleter()); ArgumentCompleter argumentCompleter = new ArgumentCompleter(argumentDelimiter, argumentCompleters); argumentCompleter.setStrict(false); this.commandCompleters.put(command.getName(), argumentCompleter); } getStrings().addAll(names); }
public CommandCompleter(ConsoleReader consoleReader, ArgumentDelimiter argumentDelimiter, Iterable<Command> commands) { this.console = consoleReader; List<String> names = new ArrayList<String>(); for (Command command : commands) { this.commands.add(command); names.add(command.getName()); List<String> options = new ArrayList<String>(); for (OptionHelp optionHelp : command.getOptionsHelp()) { options.addAll(optionHelp.getOptions()); } AggregateCompleter arguementCompleters = new AggregateCompleter( new StringsCompleter(options), new FileNameCompleter()); ArgumentCompleter argumentCompleter = new ArgumentCompleter( argumentDelimiter, arguementCompleters); argumentCompleter.setStrict(false); this.commandCompleters.put(command.getName(), argumentCompleter); } getStrings().addAll(names); }
@Inject public DefaultCompleters(Injector injector) { this.completers = ImmutableMap.<String, Completer>builder() .put(ArgumentName.APP.getName(), injector.getInstance(AppIdCompleter.class)) .put(ArgumentName.ARTIFACT_NAME.getName(), injector.getInstance(ArtifactNameCompleter.class)) .put(ArgumentName.DATASET_MODULE.getName(), injector.getInstance(DatasetModuleNameCompleter.class)) .put(ArgumentName.DATASET.getName(), injector.getInstance(DatasetNameCompleter.class)) .put(ArgumentName.DATASET_TYPE.getName(), injector.getInstance(DatasetTypeNameCompleter.class)) .put(ArgumentName.LOCAL_FILE_PATH.getName(), new FileNameCompleter()) .put(ArgumentName.APP_JAR_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.DATASET_MODULE_JAR_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.ARTIFACT_CONFIG_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.APP_CONFIG_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.HTTP_METHOD.getName(), new EndpointCompleter()) .put(ArgumentName.ENDPOINT.getName(), new EndpointCompleter()) .put(ArgumentName.RUN_STATUS.getName(), new EnumCompleter(ProgramRunStatus.class)) .put(ArgumentName.NAMESPACE_NAME.getName(), injector.getInstance(NamespaceNameCompleter.class)) .put(ArgumentName.COMMAND_CATEGORY.getName(), new EnumCompleter(CommandCategory.class)) .put(ArgumentName.TABLE_RENDERER.getName(), new EnumCompleter(RenderAsCommand.Type.class)) .put(ArgumentName.WORKFLOW_TOKEN_SCOPE.getName(), new EnumCompleter(WorkflowToken.Scope.class)) .put(ArgumentName.TARGET_TYPE.getName(), new EnumCompleter(EntityTypeSimpleName.class)) .put(ArgumentName.METADATA_SCOPE.getName(), new EnumCompleter(MetadataScope.class)) .put(ArgumentName.PRINCIPAL_TYPE.getName(), new EnumCompleter(Principal.PrincipalType.class)) .putAll(generateProgramIdCompleters(injector)).build(); }
public CheckSSLHandshake() { super("check-ssl-handshake"); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Check SSL handshake to a given server."); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); final FileNameCompleter c = new FileNameCompleter(); this.completers.put(KEYSTORE_FILE_SHORT_OPTION, c); }
private static String readTrace(String trace, ConsoleReader cr) throws IOException { Completer c = new FileNameCompleter(); try { cr.addCompleter(c); cr.setPrompt("Select the script to deploy: "); while (trace == null || trace.isEmpty()) { cr.flush(); trace = cr.readLine().trim(); } return trace; } finally { cr.removeCompleter(c); } }
private ConsoleReader getConsoleReader() { ConsoleReader reader; try { reader = new ConsoleReader(); } catch (IOException e) { throw KEMException.internalError("IO error detected interacting with console", e); } reader.setBellEnabled(false); List<String> singleLevelCommands = Arrays.<String>asList("step", "s", "S", "b", "B", "back-step", "j", "J", "jump-to", "quit", "abort", "exit", "src", "source", "checkpoint", "ch", "resume", "run", "r", "p", "peek", "remwatch", "xwatch", "show", "get-states", "gs", "select", "copy", "cp", "watch", "w"); List<String> multiLevelCommands = Arrays.<String>asList("source", "src"); List<Completer> completers = singleLevelCommands .stream() .map(command -> (Completer) new ArgumentCompleter(new StringsCompleter(command), new NullCompleter())) .collect(Collectors.toList()); multiLevelCommands.stream() .forEach(command -> completers.add(new ArgumentCompleter(new StringsCompleter(command), new FileNameCompleter()))); reader.addCompleter(new AggregateCompleter(completers)); return reader; }
@Inject public DefaultCompleters(Injector injector) { this.completers = ImmutableMap.<String, Completer>builder() .put(ArgumentName.APP.getName(), injector.getInstance(AppIdCompleter.class)) .put(ArgumentName.ARTIFACT_NAME.getName(), injector.getInstance(ArtifactNameCompleter.class)) .put(ArgumentName.DATASET_MODULE.getName(), injector.getInstance(DatasetModuleNameCompleter.class)) .put(ArgumentName.DATASET.getName(), injector.getInstance(DatasetNameCompleter.class)) .put(ArgumentName.DATASET_TYPE.getName(), injector.getInstance(DatasetTypeNameCompleter.class)) .put(ArgumentName.STREAM.getName(), injector.getInstance(StreamIdCompleter.class)) .put(ArgumentName.LOCAL_FILE_PATH.getName(), new FileNameCompleter()) .put(ArgumentName.APP_JAR_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.DATASET_MODULE_JAR_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.ARTIFACT_CONFIG_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.APP_CONFIG_FILE.getName(), new FileNameCompleter()) .put(ArgumentName.HTTP_METHOD.getName(), new EndpointCompleter()) .put(ArgumentName.ENDPOINT.getName(), new EndpointCompleter()) .put(ArgumentName.RUN_STATUS.getName(), new EnumCompleter(ProgramRunStatus.class)) .put(ArgumentName.NAMESPACE_NAME.getName(), injector.getInstance(NamespaceNameCompleter.class)) .put(ArgumentName.COMMAND_CATEGORY.getName(), new EnumCompleter(CommandCategory.class)) .put(ArgumentName.TABLE_RENDERER.getName(), new EnumCompleter(RenderAsCommand.Type.class)) .put(ArgumentName.WORKFLOW_TOKEN_SCOPE.getName(), new EnumCompleter(WorkflowToken.Scope.class)) .put(ArgumentName.TARGET_TYPE.getName(), new EnumCompleter(EntityTypeSimpleName.class)) .put(ArgumentName.METADATA_SCOPE.getName(), new EnumCompleter(MetadataScope.class)) .put(ArgumentName.FORMAT.getName(), new StringsCompleter(Formats.ALL)) .put(ArgumentName.PRINCIPAL_TYPE.getName(), new EnumCompleter(Principal.PrincipalType.class)) .putAll(generateProgramIdCompleters(injector)).build(); }
public ReloadConfiguration() { super("reload-configuration"); this.setUsage(CommandUtil.formatCommandUsage(this)); this.setDescription("Reload placeholders configuration a JBI component"); this.setOptionsDescription(CommandUtil.formatCommandOptionsDescription(this)); this.completers.put(URL_SHORT_OPTION, new FileNameCompleter()); }
import java.io.IOException; import jline.TerminalFactory; import jline.console.ConsoleReader; import jline.console.completer.FileNameCompleter; public class MyJLineShell { public static void main(String[] args) { try { ConsoleReader console = new ConsoleReader(); console.addCompleter(new FileNameCompleter()); console.setPrompt("prompt> "); String line = null; while ((line = console.readLine()) != null) { console.println(line); } } catch (IOException e) { e.printStackTrace(); } finally { try { TerminalFactory.get().restore(); } catch (Exception e) { e.printStackTrace(); } } } }
/** * Main entry point to the SQL CLI interface in MacroBase * * @param userWantsPaging try to enable paging of results in SQL shell * @throws IOException if unable to instantiate ConsoleReader */ private MacroBaseSQLRepl(final boolean userWantsPaging) throws IOException { // First try to turn paging on this.paging = enablePaging(userWantsPaging); // Initialize console reader and writer reader = new ConsoleReader(); final CandidateListCompletionHandler handler = new CandidateListCompletionHandler(); handler.setStripAnsi(true); reader.setCompletionHandler(handler); reader.addCompleter(new FileNameCompleter()); parser = new SqlParser(); queryEngine = new QueryEngine(); }