/** * Adds a group. * @param command the group command * @param configurator the group configurator * @return this */ default CommandBuilder<T> addGroup(T command, Consumer<? super CommandBuilder<T>> configurator) { return addGroup(Util.getCommandName(command), command, configurator); }
/** * Adds a leaf command. * @param command the command object * @return this */ default CommandBuilder<T> addCommand(T command) { return addCommand(Util.getCommandName(command), command); }
@Override public JCommanderWrapper<T> addGroup(T command, Consumer<? super CommandBuilder<T>> configurator) { root.addGroup(command, configurator); return this; }
@Override public void accept(CommandBuilder<Runnable> builder) { builder.addGroup(new DdlGroup(), group -> group .addCommand(new DdlHiveCommand())); } }
/** * Returns the transaction ID. * @return the transaction ID */ public String getId() { return Optional.ofNullable(transactionId) .orElseThrow(() -> new CommandConfigurationException( "transaction ID (execution ID of the target jobflow) must be specified")); } }
@Override public void accept(CommandBuilder<Runnable> builder) { builder.addCommand(new RunCommand()); } }
@Override public void accept(CommandBuilder<Runnable> builder) { builder.addGroup(new ConfigurationGroup(), flattern()::accept); }
private static void handle(CommandConfigurationException e) { LOG.error("{}", e.getMessage()); }
private static void handle(ParameterException e) { JCommanderWrapper.handle(e, s -> LOG.error("{}", s)); //$NON-NLS-1$ } }
private static Params collectParams(JCommander commander) { Params results = new Params(); commander.getObjects().forEach(it -> collectParams(results, it)); return results; }
/** * Returns all transaction information. * @return transaction information */ public List<TransactionInfo> list() { LOG.debug("loading all transaction info"); try { return getEditor().list(); } catch (IOException e) { throw new CommandExecutionException("error occurred while loading transactions", e); } }
@Override public JCommanderWrapper<T> addCommand(T command) { root.addCommand(command); return this; }
/** * Configures this object. * @param configurator the configurator * @return this */ @Override public JCommanderWrapper<T> configure(Consumer<? super CommandBuilder<T>> configurator) { root.configure(configurator); return this; }
@Override public CommandBuilder<T> addCommand(String name, T command) { add(name, command); return this; }
/** * Creates a new instance. * @param programName the program name {@code $0} * @param command the root command */ public JCommanderWrapper(String programName, Object command) { JCommander commander = new JCommander(); commander.setProgramName(programName); commander.addObject(command); this.root = new Builder<>(new String[] { programName }, commander); }
/** * Returns a {@link CommandProvider} which adds the group commands. * @return flattened {@link CommandProvider} of this */ public CommandProvider flattern() { return builder -> builder .addCommand(new ConfigurationSystemCommand()) .addCommand(new ConfigurationListCommand()); } }
@Override public void accept(CommandBuilder<Runnable> builder) { builder.addGroup(new TransactionGroup(), flattern()::accept); }
@Override public JCommanderWrapper<T> addGroup(String name, T command, Consumer<? super CommandBuilder<T>> configurator) { root.addGroup(name, command, configurator); return this; }
@Override public JCommanderWrapper<T> addCommand(String name, T command) { root.addCommand(name, command); return this; }
@Override public void accept(CommandBuilder<Runnable> builder) { builder.addGroup(new FileGroup(), flattern()::accept); }