class OptionsParser {

    static Options parse(String[] args) throws OptionsException {
        if (args.length == 0) {
            throw new OptionsException("No sub-command provided. " + AVAILABLE_COMMANDS_MSG);
        }
        String subCommand = args[0];
        switch (subCommand) {
            case "send":
                return parseSendCommand(args);
            case "run":
                return parseRunCommand(args);
            case "serve":
                return parseServeCommand(args);
            case "help":
            case "-h":
                HelpOptions helpOptions = HelpOptions.GENERAL;
                if (args.length > 1) try {
                    helpOptions = HelpOptions.valueOf(args[1].toUpperCase());
                } catch (IllegalArgumentException e) {
                    // ignore invalid option
                }
                return Options.justShowHelp(helpOptions);
            default:
                throw new OptionsException("Unknown sub-command: " + subCommand + ". " +
                        AVAILABLE_COMMANDS_MSG);
        }
    }

}