@Command public String home() { return System.getProperty("user.home"); }
public static String name(final Method method) { final Command command = method.getAnnotation(Command.class); if (command == null) { return method.getName(); } return value(command.value(), method.getName()); }
public CmdMethod(final Method method, final Target target, final DefaultsContext defaultsFinder) { this.target = target; this.method = method; this.defaultsFinder = defaultsFinder; this.name = Commands.name(method); final List<Param> parameters = buildParams(null, NO_PREFIX, null, Reflection.params(method)); this.parameters = Collections.unmodifiableList(parameters); final Command cmdAnnotation = method.getAnnotation(Command.class); this.interceptors = cmdAnnotation == null ? null : cmdAnnotation.interceptedBy(); validate(); }
@Command public String dir() { return System.getProperty("user.dir"); }
public static String name(final Class<?> clazz) { final Command command = clazz.getAnnotation(Command.class); final String defaultName = Strings.lcfirst(clazz.getSimpleName()); if (command == null) { return defaultName; } return value(command.value(), defaultName); }
@Command("get") public String doGet(String key) { return properties.getProperty(key); }
@Command public void gc() { Runtime.getRuntime().gc(); }
@Command public int processors() { return Runtime.getRuntime().availableProcessors(); }
@Command public String date() { return String.format("%tc", System.currentTimeMillis()); }
@Command("kibana") public final class KibanaCommands {
@Command public static void exit() { if (exitHook != null) { exitHook.run(); } Environment.ENVIRONMENT_THREAD_LOCAL.remove(); throw new ExitException(); }
@Command("list") public String doList(@Option({"pattern", "p"}) Pattern pattern) { if (pattern == null) pattern = Pattern.compile(".*"); final StringBuilder sb = new StringBuilder(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { final String key = entry.getKey().toString(); if (pattern.matcher(key).matches()) { sb.append(key).append(" = ").append(entry.getValue()).append("\n"); } } return sb.toString(); } }
@Command("set") public String doSet(@Option({"key", "k"}) String key, @Option({"value", "v"}) String value) { final Object old = properties.setProperty(key, value); final StringBuilder sb = new StringBuilder(); sb.append("set ").append(key).append(" to ").append(value); sb.append("\n"); if (old != null) { sb.append("old value: ").append(old); sb.append("\n"); } return sb.toString(); }
@Command public void exit() throws StopException { throw new StopException(); } }
@Command public void exit() throws StopException { throw new StopException(); } }
@Command public String home(@Exists @Directory File file) { return System.setProperty("user.home", file.getAbsolutePath()); }
@Command public String dir(@Exists @Directory File file) { return System.setProperty("user.dir", file.getAbsolutePath()); }
@Command public String env() { final PrintString out = new PrintString(); final Map<String, String> env = System.getenv(); for (String key : new TreeSet<String>(env.keySet())) { out.printf("%s = %s%n", key, env.get(key)); } return out.toString(); }
@Command public String whoami() { return context.getCallerPrincipal() == null ? "Unknown" : context.getCallerPrincipal().getName(); } }