private Subparser parse(final Subparsers subparsers, final String name) { final Subparser subparser = subparsers.addParser(name, true); addGlobalArgs(subparser, cliConfig); return subparser; } }
private void addCommand(Command command) { commands.put(command.getName(), command); parser.addSubparsers().help("available commands"); final Subparser subparser = parser.addSubparsers().addParser(command.getName(), false); command.configure(subparser); addHelp(subparser); subparser.description(command.getDescription()) .setDefault(COMMAND_NAME_ATTR, command.getName()) .defaultHelp(true); }
.title("subcommands") .dest("command") .description("valid subcommands") .help("additional help"); Subparser subparser = subparsers.addParser(entry.getKey()); entry.getValue().attachToSubparser(subparser);
public static Set<ClassPath.ClassInfo> findSubcommands(ArgumentParser parser) throws IOException { Subparsers subparsers = parser.addSubparsers() .dest(Constants.COMMAND) .help("FEATURE") .title("subcommands") .description("Specify which feature to perform") .metavar("COMMAND"); Set<ClassPath.ClassInfo> allClasses = new TreeSet<>(Comparator.comparing(ClassPath.ClassInfo::getName)); ClassPath classpath = ClassPath.from(CommandLine.class.getClassLoader()); allClasses.addAll(classpath.getTopLevelClasses("com.salesforce.dockerfileimageupdate.subcommands.impl")); allClasses = allClasses.stream() .filter(classInfo -> !classInfo.getName().endsWith("Test")) .collect(Collectors.toSet()); for (ClassPath.ClassInfo classInfo : allClasses) { handleAnnotations(classInfo, subparsers); } return allClasses; }
/** * The logic for running DiffyTool has been captured in a helper method that returns a boolean to facilitate unit testing. * Since System.exit terminates the JVM it would not be practical to test the main method. * * @param args the arguments from the command line input * @return true if two inputs were read with no differences, false if differences were found or an error was encountered */ protected static boolean runJolt( String[] args ) { ArgumentParser parser = ArgumentParsers.newArgumentParser( "jolt" ); Subparsers subparsers = parser.addSubparsers().help( "transform: given a Jolt transform spec, runs the specified transforms on the input data.\n" + "diffy: diff two JSON documents.\n" + "sort: sort a JSON document alphabetically for human readability." ); for ( Map.Entry<String, JoltCliProcessor> entry : JOLT_CLI_PROCESSOR_MAP.entrySet() ) { entry.getValue().intializeSubCommand( subparsers ); } Namespace ns; try { ns = parser.parseArgs( args ); } catch ( ArgumentParserException e ) { parser.handleError( e ); return false; } JoltCliProcessor joltToolProcessor = JOLT_CLI_PROCESSOR_MAP.get( args[0] ); if ( joltToolProcessor != null ) { return joltToolProcessor.process( ns ); } else { // TODO: error message, print usage. although I don't think it will ever get to this point. return false; } }
public static Set<ClassPath.ClassInfo> findSubcommands(ArgumentParser parser) throws IOException { Subparsers subparsers = parser.addSubparsers() .dest(Constants.COMMAND) .help("FEATURE") .title("subcommands") .description("Specify which feature to perform") .metavar("COMMAND"); Set<ClassPath.ClassInfo> allClasses = new TreeSet<>(Comparator.comparing(ClassPath.ClassInfo::getName)); ClassPath classpath = ClassPath.from(CommandLine.class.getClassLoader()); allClasses.addAll(classpath.getTopLevelClasses("com.salesforce.dockerfileimageupdate.subcommands.impl")); allClasses = allClasses.stream() .filter(classInfo -> !classInfo.getName().endsWith("Test")) .collect(Collectors.toSet()); for (ClassPath.ClassInfo classInfo : allClasses) { handleAnnotations(classInfo, subparsers); } return allClasses; }
@Override public void configure(Subparser subparser) { for (AbstractLiquibaseCommand<T> subcommand : subcommands.values()) { final Subparser cmdParser = subparser.addSubparsers() .addParser(subcommand.getName()) .setDefault(COMMAND_NAME_ATTR, subcommand.getName()) .description(subcommand.getDescription()); subcommand.configure(cmdParser); } }
private void addCommand(Command command) { commands.put(command.getName(), command); parser.addSubparsers().help("available commands"); final Subparser subparser = parser.addSubparsers().addParser(command.getName(), false); command.configure(subparser); addHelp(subparser); subparser.description(command.getDescription()) .setDefault(COMMAND_NAME_ATTR, command.getName()) .defaultHelp(true); }
@Override public void configure(Subparser subparser) { for (AbstractLiquibaseCommand<T> subcommand : subcommands.values()) { final Subparser cmdParser = subparser.addSubparsers() .addParser(subcommand.getName()) .setDefault(COMMAND_NAME_ATTR, subcommand.getName()) .description(subcommand.getDescription()); subcommand.configure(cmdParser); } }
private void addCommand(Command command) { commands.put(command.getName(), command); parser.addSubparsers().help("available commands"); final Subparser subparser = parser.addSubparsers().addParser(command.getName(), false); command.configure(subparser); addHelp(subparser); subparser.description(command.getDescription()) .setDefault(COMMAND_NAME_ATTR, command.getName()) .defaultHelp(true); }
private Subparser p(final Subparsers subparsers, final String name) { final Subparser subparser = subparsers.addParser(name, true); addGlobalArgs(subparser, cliConfig); return subparser; } }
private void addCommand(Subparser subparser, Command command) { commands.put(command.getName(), command); subparser.addSubparsers().help("available commands"); final Subparser commandSubparser = subparser.addSubparsers().addParser(command.getName(), false); command.configure(commandSubparser); commandSubparser.addArgument("-h", "--help") .action(new HelpArgumentAction()) .help("show this help message and exit") .setDefault(Arguments.SUPPRESS); commandSubparser.description(command.getDescription()) .setDefault(COMMAND_NAME_ATTR, command.getName()) .defaultHelp(true); }
private static Subparser addSubparser(Subparsers subCommands, String name, CliContext cliContext) { final Subparser parser = subCommands.addParser(name); GlobalOptions.add(parser, cliContext, true); return parser; }
/** * Initialize the arg parser for the Sort sub command * * @param subparsers The Subparsers object to attach the new Subparser to */ @Override public void intializeSubCommand( Subparsers subparsers ) { Subparser sortParser = subparsers.addParser( "sort" ) .description( "Jolt CLI Sort Tool. This tool will ingest one JSON input (from a file or standard input) and " + "perform the Jolt sort operation on it. The sort order is standard alphabetical ascending, with a " + "special case for \"~\" prefixed keys to be bumped to the top. The program will return an exit code " + "of 0 if the sort operation is performed successfully or a 1 if an error is encountered." ) .defaultHelp( true ); sortParser.addArgument( "input" ).help( "File path to the input JSON that the sort operation should be performed on. " + "This file should contain valid JSON. " + "If this argument is not specified then standard input will be used." ) .type( Arguments.fileType().verifyExists().verifyIsFile().verifyCanRead() ) .nargs( "?" ).setDefault( (File) null ).required( false ); // these last two method calls make input optional sortParser.addArgument( "-u" ).help( "Turns off pretty print for the output. Output will be raw json with no formatting." ) .action( Arguments.storeTrue() ); }
/** * Initialize the arg parser for the Transform sub command * * @param subparsers The Subparsers object to attach the new Subparser to */ @Override public void intializeSubCommand( Subparsers subparsers ) { Subparser transformParser = subparsers.addParser( "transform" ) .description( "Jolt CLI Transform Tool. This tool will ingest a JSON spec file and an JSON input (from a file or " + "standard input) and run the transforms specified in the spec file on the input. The program will return an " + "exit code of 0 if the input is transformed successfully or a 1 if an error is encountered" ) .defaultHelp( true ); File nullFile = null; transformParser.addArgument( "spec" ).help( "File path to Jolt Transform Spec to execute on the input. " + "This file should contain valid JSON." ) .type( Arguments.fileType().verifyExists().verifyIsFile().verifyCanRead() ); transformParser.addArgument( "input" ).help( "File path to the input JSON for the Jolt Transform operation. " + "This file should contain valid JSON. " + "If this argument is not specified then standard input will be used." ) .type( Arguments.fileType().verifyExists().verifyIsFile().verifyCanRead() ) .nargs( "?" ).setDefault( nullFile ); // these last two method calls make input optional transformParser.addArgument( "-u" ).help( "Turns off pretty print for the output. Output will be raw json with no formatting." ) .action( Arguments.storeTrue() ); }
/** * Initialize the arg parser for the Diffy sub command * * @param subparsers The Subparsers object to attach the new Subparser to */ @Override public void intializeSubCommand( Subparsers subparsers ) { Subparser diffyParser = subparsers.addParser( "diffy" ) .description( "Jolt CLI Diffy Tool. This tool will ingest two JSON inputs (from files or standard input) and " + "perform the Jolt Diffy operation to detect any differences. The program will return an exit code of " + "0 if no differences are found or a 1 if a difference is found or an error is encountered." ) .defaultHelp( true ); diffyParser.addArgument( "filePath1" ).help( "File path to feed to Input #1 for the Diffy operation. " + "This file should contain valid JSON." ) .type( Arguments.fileType().verifyExists().verifyIsFile().verifyCanRead() ); diffyParser.addArgument( "filePath2" ).help( "File path to feed to Input #2 for the Diffy operation. " + "This file should contain valid JSON. " + "If this argument is not specified then standard input will be used." ) .type( Arguments.fileType().verifyExists().verifyIsFile().verifyCanRead() ) .nargs( "?" ).setDefault( (File) null ); // these last two method calls make filePath2 optional diffyParser.addArgument( "-s" ).help( "Diffy will suppress output and run silently." ) .action( Arguments.storeTrue() ); diffyParser.addArgument( "-a" ).help( "Diffy will not consider array order when detecting differences" ) .action( Arguments.storeTrue() ); }
/** * Construct a CLI object with the three sub-parsers to manage the command * line parameters. */ public CLI() { this.annotateParser = this.subParsers.addParser("tag").help("Tagging CLI"); loadAnnotateParameters(); this.trainParser = this.subParsers.addParser("train").help("Training CLI"); loadTrainingParameters(); this.evalParser = this.subParsers.addParser("eval").help("Evaluation CLI"); loadEvalParameters(); this.crossValidateParser = this.subParsers.addParser("cross").help( "Cross validation CLI"); loadCrossValidateParameters(); serverParser = subParsers.addParser("server").help("Start TCP socket server"); loadServerParameters(); clientParser = subParsers.addParser("client").help("Send queries to the TCP socket server"); loadClientParameters(); }