private static String readLine(ConsoleReader reader, String prompt) throws IOException { String earlierLine = reader.getCursorBuffer().toString(); String readLine; try { readLine = reader.readLine(prompt); } catch (IndexOutOfBoundsException e) { if (earlierLine.length() == 0) { reader.println(); readLine = LINE_SEPARATOR; reader.getCursorBuffer().cursor = 0; } else { readLine = readLine(reader, prompt); } } return readLine; }
@Override public void print(String s) { try { reader.println(s); } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Clear the screen by issuing the ANSI "clear screen" code. */ public boolean clearScreen() throws IOException { if (!tputs("clear_screen")) { println(); } return true; }
public void println(final CharSequence s) throws IOException { print(s); println(); }
private void logError(String s) { log.error(s); if (logErrorsToConsole) { try { reader.println("ERROR: " + s); reader.flush(); } catch (IOException e) {} } }
@Override protected void message(String fmt, Object... args) { if (finalVerbose) { try { shellState.getReader().println(String.format(fmt, args)); } catch (IOException ex) { throw new RuntimeException(ex); } } } };
private void rawPrintln(final String s) throws IOException { rawPrint(s); println(); }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException { for (String p : TablePermission.printableValues()) { shellState.getReader().println(p); } return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException { for (String p : NamespacePermission.printableValues()) { shellState.getReader().println(p); } return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException { for (String p : SystemPermission.printableValues()) { shellState.getReader().println(p); } return 0; }
/** * The equivalent of hitting <RET>. The line is considered * complete and is returned. * * @return The completed line of text. */ public String accept() throws IOException { moveToEnd(); println(); // output newline flush(); return finishBuffer(); }
private void abort() throws IOException { beep(); buf.clear(); println(); redrawLine(); }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { final String tableName = OptUtil.getTableOpt(cl, shellState); final Map<String,Set<Text>> groups = shellState.getAccumuloClient().tableOperations() .getLocalityGroups(tableName); for (Entry<String,Set<Text>> entry : groups.entrySet()) { shellState.getReader() .println(entry.getKey() + "=" + LocalityGroupUtil.encodeColumnFamilies(entry.getValue())); } return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException { shellState.getReader().println(shellState.getAccumuloClient().whoami()); return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { final String user = cl.getArgs()[0]; final String p = shellState.readMaskedLine("Enter current password for '" + user + "': ", '*'); if (p == null) { shellState.getReader().println(); return 0; } // user canceled final byte[] password = p.getBytes(UTF_8); final boolean valid = shellState.getAccumuloClient().securityOperations().authenticateUser(user, new PasswordToken(password)); shellState.getReader().println((valid ? "V" : "Not v") + "alid"); return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { final String user = cl.getOptionValue(userOpt.getOpt(), shellState.getAccumuloClient().whoami()); // Sort authorizations Authorizations auths = shellState.getAccumuloClient().securityOperations() .getUserAuthorizations(user); List<String> set = sortAuthorizations(auths); shellState.getReader().println(StringUtils.join(set, ',')); return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { for (String user : shellState.getAccumuloClient().securityOperations().listLocalUsers()) { shellState.getReader().println(user); } return 0; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { final String tableName = OptUtil.getTableOpt(cl, shellState); final Text startRow = OptUtil.getStartRow(cl); final Text endRow = OptUtil.getEndRow(cl); if (!cl.hasOption(forceOpt.getOpt()) && (startRow == null || endRow == null)) { shellState.getReader() .println("Not deleting unbounded range. Specify both ends, or use --force"); return 1; } shellState.getAccumuloClient().tableOperations().deleteRows(tableName, startRow, endRow); return 0; }
@Override protected void doTableOp(final Shell shellState, final String tableName) throws Exception { shellState.getAccumuloClient().tableOperations().delete(tableName); shellState.getReader().println("Table: [" + tableName + "] has been deleted."); if (shellState.getTableName().equals(tableName)) { shellState.setTableName(""); } }