class MainCommandLine {

    public static void execute(final String... args) {
        int port = DEFAULT_PORT;
        String command = null;
        boolean debug = false;

        // Parse command-line arguments.
        int index = 0;
        while (index < args.length) {

            switch (args[index]) {
                case CMD_SILENT:
                    rootLogger.setLevel(Level.WARN);
                    consoleAppender.setThreshold(Level.WARN);
                    break;

                case CMD_DEBUG:
                    debug = true;
                    break;

                case CMD_PORT:
                    if (index >= (args.length - 1)) {
                        System.out.println("Missing port number");
                        printUsage();
                        return;
                    }
                    port = Integer.parseInt(args[index + 1]);
                    ++index;
                    break;

                default:
                    if (args[index].startsWith("-")) {
                        System.out.println("Unknown option: " + args[index]);
                        printUsage();
                        return;
                    }
                    if (command != null) {
                        System.out.println("Unknown argument: " + args[index]);
                        printUsage();
                        return;
                    }
                    command = args[index];
                    break;
            }
            ++index;
        }

        if (debug) {
            consoleAppender.setThreshold(Level.DEBUG);
        }

        if ((command != null) && command.equals(CMD_HELP)) {
            printUsage();
        } else {
            server.startServer(port);
        }
    }

    private  MainCommandLine();

}