コード例 #1
0
  public static Namespace handleArgumentString(String[] args, ArgumentParser parser) {
    Namespace parsedArgs = null;

    try {
      parsedArgs = parser.parseArgs(args);
      String selectedModule = parsedArgs.getString("Module");

      try {
        String propPath = parsedArgs.getString("propertyFile");
        if (propPath != null) {
          parsedArgs = loadProperties(propPath);

          // 선택된 모듈이 무엇이었는지 다시 기억
          parsedArgs.getAttrs().put("Module", selectedModule);
        }
      } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
      }

    } catch (ArgumentParserException e) {
      parser.handleError(e);
      System.exit(1);
    }

    // 만약 output 디렉토리가 존재하지 않으면 새로 생성
    Path outputPath = null;
    try {
      String outputPathString = parsedArgs.getString("outputDirPath");

      if (outputPathString != null) {
        outputPath = Paths.get(outputPathString);
        if (!Files.exists(outputPath)) {
          Files.createDirectories(outputPath);
        }
      }

    } catch (NullPointerException e) {
      // System.err.println();
    } catch (InvalidPathException e) {

    } catch (IOException e) {
      e.printStackTrace();
    }

    return parsedArgs;
  }