public void exec(CLIContext cli, String[] args) throws IOException { boolean shutdown; if (cli.isInteractive() && cli.getOutputStream() != System.out) { cli.println ("Can't shutdown remotely"); return; } if (hasOption(args, "-f", "--force", "-fq")) { shutdown = true; } else { shutdown = cli.confirm("Confirm shutdown (Yes/No) ? "); } if (shutdown) { if (!hasOption (args, "-q", "--quiet", "-fq")) cli.println("Shutting down."); cli.getCLI().getQ2().shutdown(); } else { cli.println("Q2 will continue running."); } }
private void showOne(CLIContext cli, String name, boolean detail) { try { Object obj = NameRegistrar.get(name); cli.println(name + " : " + obj.toString()); if (detail && obj instanceof Loggeable) { cli.printLoggeable((Loggeable) obj, ""); } } catch (NameRegistrar.NotFoundException e) { cli.println("Object not found in NameRegistrar"); } }
@Override public String getPrompt(CLIContext ctx, String[] args) { if (args.length < 2) { ctx.println ("Usage: binlog directory-name"); return null; } ctx.getUserData().put("binlog", args[1]); return String.format("(%s)> ", new File(args[1]).getName()); }
@Override public void exec(CLIContext ctx, String[] args) throws Exception { if (args.length < 2) { ctx.println("Usage: enable <xml_file(no extenssion)>"); return; } File deployDir = ctx.getCLI().getQ2().getDeployDir(); File deploy = new File(deployDir.getAbsolutePath()+"/"+args[1]+".xml"); if(deploy.exists() && deploy.isFile()){ File dest = new File(deployDir.getAbsolutePath()+"/"+args[1]+".xml.off"); deploy.renameTo(dest); ctx.println("DISABLED: " + args[1]); return; } File dest = new File(deployDir.getAbsolutePath()+"/"+args[1]+".xml.off"); if (dest.exists()) { ctx.println("Already disabled: " + args[1]); return; } ctx.println("Can't find the bean descriptor: "+args[1]); return; } }
if (cmd instanceof CLISubSystem) { CLISubSystem ss = (CLISubSystem) cmd; ctx.getCLI().setPrompt(ss.getPrompt(ctx, args), ss.getCompletionPrefixes(ctx, args)); Terminal t = ctx.getReader().getTerminal(); ((Command) cmd).exec (t.input(), t.output(), t.output(), args); ctx.printThrowable(ex); ctx.printThrowable(ex); break; ctx.println("Invalid command '" + verbatimCmd + "'");
public void exec(CLIContext cli, String[] args) throws Exception { try (BinLogReader bl = new BinLogReader(new File((String) cli.getUserData().get("binlog")))) { while (bl.hasNext(10000L)) { BinLog.Entry ref = bl.next(); cli.println(String.format("%06d@%08d %s", ref.ref().getFileNumber(), ref.ref().getOffset(), ISOUtil.hexdump(ref.get()))); cli.getReader().getTerminal().flush(); } } catch (Exception e) { e.printStackTrace(); } } }
public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("What manual page do you want?"); return; } String command = args[1]; InputStream is = getClass().getResourceAsStream(command.toUpperCase() + ".man"); if (is != null) { try { byte[] b = new byte[is.available()]; is.read(b); cli.print(new String(b)); } finally { is.close(); } } else { cli.println("No manual entry for " + command); } } }
public boolean confirm(String prompt) { return "yes".equalsIgnoreCase(getReader().readLine(prompt)); }
public void print(String s) { if (isInteractive()) getReader().getTerminal().writer().print(s); else { try { out.write(s.getBytes()); out.flush(); } catch (IOException ignored) { ignored.printStackTrace(); } } }
private void showHelp (CLIContext cli, String args[], Options options) { PrintWriter pw = new PrintWriter (cli.getOutputStream()); HelpFormatter helpFormatter = new HelpFormatter (); helpFormatter.printHelp (args[0] + "[options]", options); helpFormatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, args[0], null, options, 0, HelpFormatter.DEFAULT_DESC_PAD, null,false); } }
public void exec(CLIContext cli, String[] args) throws Exception { boolean quiet = args.length > 1 && "-q".equals (args[1]); try (BinLogWriter bl = new BinLogWriter(new File((String) cli.getUserData().get("binlog")))) { int oldFile = bl.getFileNumber(); bl.cutover(); if (!quiet) cli.print (String.format ("cutover %06d -> %06d%n", oldFile, bl.getFileNumber())); } } }
public void println(String s) { print (s + System.getProperty("line.separator")); }
@Override public String getPrompt(CLIContext ctx, String[] args) { String prefix = null; if (args.length > 1) { prefix = args[1]; if (!prefix.endsWith(".")) prefix = prefix + "."; ctx.getUserData().put(PREFIX, prefix); } else { ctx.getUserData().remove(PREFIX); } return "sysconfig" + (prefix != null ? "[" + args[1] + "]" : "") + "> "; }
@Override public void exec(CLIContext ctx, String[] args) throws Exception { if (args.length < 2) { ctx.println("Usage: enable <xml_file(no extenssion)>"); return; } File deployDir = ctx.getCLI().getQ2().getDeployDir(); File deploy = new File(deployDir.getAbsolutePath() + "/" + args[1] + ".xml.off"); if (deploy.exists() && deploy.isFile()) { File dest = new File(deployDir.getAbsolutePath() + "/" + args[1] + ".xml"); deploy.renameTo(dest); ctx.println("ENABLED: " + args[1]); return; } File dest = new File(deployDir.getAbsolutePath() + "/" + args[1] + ".xml"); if (dest.exists()) { ctx.println("Already enabled: " + args[1]); return; } ctx.println("Can't find the bean descriptor: " + args[1]); return; } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("Usage: rm <id> "); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); SysConfigManager mgr = new SysConfigManager(db); if (cli.getUserData().containsKey(SYSCONFIG.PREFIX)) mgr.setPrefix((String) cli.getUserData().get(SYSCONFIG.PREFIX)); boolean deleted = mgr.delete(args[1]); db.commit(); cli.println ("sysconfig " + (deleted ? "deleted" : "not found")); } catch (Exception e) { cli.println (e.getMessage()); } } }
private void showAll(CLIContext cli, boolean detail) { NameRegistrar nr = NameRegistrar.getInstance(); int maxw = 0; Iterator iter = NameRegistrar.getAsMap().entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); maxw = Math.max(maxw, entry.getKey().toString().length()); } iter = NameRegistrar.getAsMap().entrySet().iterator(); maxw++; while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); cli.println( ISOUtil.strpad(entry.getKey().toString(), maxw) + entry.getValue().toString() ); if (detail && entry.getValue() instanceof Loggeable) { cli.printLoggeable((Loggeable) entry.getValue(), " "); } } } }
public void exec(CLIContext ctx, String[] args) throws Exception { ctx.getReader().getTerminal().puts(InfoCmp.Capability.clear_screen); } }