docs: public void runArgs(String[] args) {
          CommandLineParser clParser = new DefaultParser();
          CommandLine line;
          String host;
          String port;
          CMD cmd;
          String[] cmdArgs;
          final PrintStream CONSOLE = System.out;
          try {
              // parse the command line arguments
              line = clParser.parse(options, args);
  
              if (line.hasOption("output")){
                  String location = line.getOptionValue("output");
                  File output = new File(location);
                  FileOutputStream fos;
                  try {
                      fos = new FileOutputStream(output);
                  } catch (FileNotFoundException e) {
                      e.printStackTrace();
                      throw new ParseException(String.format("Wrong -o option. args %s\n",Arrays.asList(args)));
                  }
                  PrintStream out = new PrintStream(fos);
                  System.setOut(out);
  
              }
              if (line.getOptions().length==0 || line.hasOption("help")) {
                  if ((line.getOptions().length > 2) || (line.getOptions().length==2 && !line.hasOption("output"))){
                      throw new ParseException(String.format("Wrong -help option. args %s\n", Arrays.asList(args)));
                  }
                  printUsage(System.out);
              }
              if (line.hasOption("server")) {
                  String server = line.getOptionValue("server");
                  try {
                      host = server.split(":")[0];
                      port = server.split(":")[1];
                  }catch (Exception e){
                      throw new ParseException(String.format("Wrong -server option. args %s\n", Arrays.asList(args)));
                  }
                  ServiceDirectory.getServiceDirectoryConfig().setProperty(
                          DirectoryServiceRestfulClient.SD_API_SD_SERVER_FQDN_PROPERTY,
                          host);
                  ServiceDirectory.getServiceDirectoryConfig().setProperty(
                          DirectoryServiceRestfulClient.SD_API_SD_SERVER_PORT_PROPERTY,
                          port);
              }
  
              if (line.hasOption("exec")) {
                  String commandString = line.getOptionValue("exec");
                  cmdArgs = parseCommand(commandString);
                  try {
                      cmd = CMD.valueOf(cmdArgs[0]);
                  } catch (IllegalArgumentException e) {
                      throw new ParseException(String.format("Unknown command [ %s ] \n", commandString));
                  }
                  if (cmd.sizeOfArgs + 1 != cmdArgs.length) {
                      throw new ParseException(
                              String.format("Wrong arguments number for command %s, required %s but %s \n",
                                      cmdArgs[0], cmd.sizeOfArgs, cmdArgs.length - 1));
                  }
                  switch (cmd) {
                      case getInstanceOf:
                          lookupInstance(cmdArgs);
                          break;
                      case getAllInstancesOf:
                          lookupInstances(cmdArgs);
                          break;
                      case getAllServices:
                          getAllServices();
                          break;
                      case registerService:
                          registerService(cmdArgs);
                          break;
                      default:
                          fail("command " + cmd + " is unsupported yet");
                          break;
                  }
  
              }
          } catch (ParseException exp) {
              // oops, something went wrong
              exp.printStackTrace();
              try {
                  TimeUnit.MILLISECONDS.sleep(100L);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              printUsage(System.err);
          }
          System.setOut(CONSOLE);
      }