public static CommandLine buildCommand()

in tools/query_verification/src/main/java/com/google/bigquery/Main.java [113:144]


    public static CommandLine buildCommand(String[] args) {
        CommandLineParser parser = new DefaultParser();
        Options options = buildOptions();

        HelpFormatter formatter = new HelpFormatter();
        formatter.setOptionComparator(new Comparator<Option>() {
            public int compare(Option o1, Option o2) {
                if (o1.isRequired() != o2.isRequired())
                    return o1.isRequired() ? -1 : 1;
                else if (o1.hasArg() != o2.hasArg())
                    return o1.hasArg() ? -1 : 1;
                else
                    return o1.getLongOpt().compareTo(o2.getLongOpt());
            }
        });

        CommandLine command;
        try {
            command = parser.parse(options, args);
        } catch (ParseException e) {
            System.out.println(e.getMessage());
            formatter.printHelp("query_verification", options, true);
            return null;
        }

        // Help
        if (command.hasOption("h")) {
            formatter.printHelp("query_verification", options, true);
        }

        return command;
    }