ServerOptionsProcessorResponse parse(String[] argv) {
      try {
        commandLine = new GnuParser().parse(options, argv);
        // Process --hiveconf
        // Get hiveconf param values and set the System property values
        Properties confProps = commandLine.getOptionProperties("hiveconf");
        for (String propKey : confProps.stringPropertyNames()) {
          // save logging message for log4j output latter after log4j initialize properly
          debugMessage.append("Setting " + propKey + "=" + confProps.getProperty(propKey) + ";\n");
          if ("hive.log.file".equals(propKey) ||
              "hive.log.dir".equals(propKey) ||
              "hive.root.logger".equals(propKey)) {
            throw new IllegalArgumentException("Logs will be split in two "
                + "files if the commandline argument " + propKey + " is "
                + "used. To prevent this use to HADOOP_CLIENT_OPTS -D"
                + propKey + "=" + confProps.getProperty(propKey)
                + " or use the set the value in the configuration file"
                + " (see HIVE-19886)");
          }
          HiveConf.overrides.put(propKey, confProps.getProperty(propKey));
        }

        // Process --help
        if (commandLine.hasOption('H')) {
          return new ServerOptionsProcessorResponse(new HelpOptionExecutor(serverName, options));
        }

        // Process --deregister
        if (commandLine.hasOption("deregister")) {
          return new ServerOptionsProcessorResponse(new DeregisterOptionExecutor(
              commandLine.getOptionValue("deregister")));
        }

        // Process --listHAPeers
        if (commandLine.hasOption("listHAPeers")) {
          return new ServerOptionsProcessorResponse(new ListHAPeersExecutor());
        }

        // Process --failover
        if (commandLine.hasOption("failover")) {
          return new ServerOptionsProcessorResponse(new FailoverHS2InstanceExecutor(
            commandLine.getOptionValue("failover")
          ));
        }

        // Process --getHiveConf
        if (commandLine.hasOption("getHiveConf")) {
          return new ServerOptionsProcessorResponse(() -> {
            String key = commandLine.getOptionValue("getHiveConf");
            HiveConf hiveConf = new HiveConf();
            HiveConf.ConfVars confVars = HiveConf.getConfVars(key);
            String value = hiveConf.get(key);
            if (confVars != null && confVars.getValidator() instanceof Validator.TimeValidator) {
              Validator.TimeValidator validator = (Validator.TimeValidator) confVars.getValidator();
              value = HiveConf.getTimeVar(hiveConf, confVars, validator.getTimeUnit()) + "";
            }
            System.out.println(key + "=" + value);
          });
        }
      } catch (ParseException e) {
        // Error out & exit - we were not able to parse the args successfully
        System.err.println("Error starting HiveServer2 with given arguments: ");
        System.err.println(e.getMessage());
        System.exit(-1);
      }
      // Default executor, when no option is specified
      return new ServerOptionsProcessorResponse(new StartOptionExecutor());
    }
ServerOptionsProcessor.
Process arguments given to HiveServer2 (-hiveconf property=value)
Set properties in System properties
Create an appropriate response object,
which has executor to execute the appropriate command based on the parsed options.
service/src/java/org/apache/hive/service/server/HiveServer2.java