public static void main()

in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportData.java [66:234]


  public static void main(String[] args) throws IoTDBConnectionException {
    Options helpOptions = OptionsUtil.createHelpOptions();
    Options tsFileOptions = OptionsUtil.createImportTsFileOptions();
    Options csvOptions = OptionsUtil.createImportCsvOptions();
    Options sqlOptions = OptionsUtil.createImportSqlOptions();
    HelpFormatter hf = new HelpFormatter();
    hf.setOptionComparator(null);
    hf.setWidth(Constants.MAX_HELP_CONSOLE_WIDTH);
    CommandLine commandLine = null;
    CommandLineParser parser = new DefaultParser();

    if (args == null || args.length == 0) {
      printHelpOptions(
          Constants.IMPORT_CLI_HEAD,
          Constants.IMPORT_CLI_PREFIX,
          hf,
          tsFileOptions,
          csvOptions,
          sqlOptions,
          true);
      System.exit(Constants.CODE_ERROR);
    }
    try {
      commandLine = parser.parse(helpOptions, args, true);
    } catch (org.apache.commons.cli.ParseException e) {
      printHelpOptions(
          Constants.IMPORT_CLI_HEAD,
          Constants.IMPORT_CLI_PREFIX,
          hf,
          tsFileOptions,
          csvOptions,
          sqlOptions,
          true);
      System.exit(Constants.CODE_ERROR);
    }
    final List<String> argList = Arrays.asList(args);
    int helpIndex = argList.indexOf(Constants.MINUS + Constants.HELP_ARGS);
    int sql_dialect = argList.indexOf(Constants.MINUS + Constants.SQL_DIALECT_ARGS); // -sql_dialect
    if (sql_dialect >= 0
        && !Constants.SQL_DIALECT_VALUE_TREE.equalsIgnoreCase(argList.get(sql_dialect + 1))) {
      final String sqlDialectValue = argList.get(sql_dialect + 1);
      if (Constants.SQL_DIALECT_VALUE_TABLE.equalsIgnoreCase(sqlDialectValue)) {
        sqlDialectTree = false;
        tsFileOptions = OptionsUtil.createTableImportTsFileOptions();
        csvOptions = OptionsUtil.createTableImportCsvOptions();
        sqlOptions = OptionsUtil.createTableImportSqlOptions();
      } else {
        ioTPrinter.println(String.format("sql_dialect %s is not support", sqlDialectValue));
        printHelpOptions(
            Constants.IMPORT_CLI_HEAD,
            Constants.IMPORT_CLI_PREFIX,
            hf,
            tsFileOptions,
            csvOptions,
            sqlOptions,
            true);
        System.exit(Constants.CODE_ERROR);
      }
    }
    int ftIndex = argList.indexOf(Constants.MINUS + Constants.FILE_TYPE_ARGS); // -ft
    if (ftIndex < 0) {
      ftIndex = argList.indexOf(Constants.MINUS + Constants.FILE_TYPE_NAME); // -file_type
    }
    if (helpIndex >= 0) {
      fileType = argList.get(helpIndex + 1);
      if (StringUtils.isNotBlank(fileType)) {
        if (Constants.TSFILE_SUFFIXS.equalsIgnoreCase(fileType)) {
          printHelpOptions(null, Constants.IMPORT_CLI_PREFIX, hf, tsFileOptions, null, null, false);
        } else if (Constants.CSV_SUFFIXS.equalsIgnoreCase(fileType)) {
          printHelpOptions(null, Constants.IMPORT_CLI_PREFIX, hf, null, csvOptions, null, false);
        } else if (Constants.SQL_SUFFIXS.equalsIgnoreCase(fileType)) {
          printHelpOptions(null, Constants.IMPORT_CLI_PREFIX, hf, null, null, sqlOptions, false);
        } else {
          ioTPrinter.println(String.format("File type %s is not support", fileType));
          printHelpOptions(
              Constants.IMPORT_CLI_HEAD,
              Constants.IMPORT_CLI_PREFIX,
              hf,
              tsFileOptions,
              csvOptions,
              sqlOptions,
              true);
        }
      } else {
        printHelpOptions(
            Constants.IMPORT_CLI_HEAD,
            Constants.IMPORT_CLI_PREFIX,
            hf,
            tsFileOptions,
            csvOptions,
            sqlOptions,
            true);
      }
      System.exit(Constants.CODE_ERROR);
    } else if (ftIndex >= 0) {
      fileType = argList.get(ftIndex + 1);
      if (StringUtils.isNotBlank(fileType)) {
        if (Constants.TSFILE_SUFFIXS.equalsIgnoreCase(fileType)) {
          try {
            commandLine = parser.parse(tsFileOptions, args);
          } catch (ParseException e) {
            ioTPrinter.println("Parse error: " + e.getMessage());
            printHelpOptions(
                null, Constants.IMPORT_CLI_PREFIX, hf, tsFileOptions, null, null, false);
            System.exit(Constants.CODE_ERROR);
          }
        } else if (Constants.CSV_SUFFIXS.equalsIgnoreCase(fileType)) {
          try {
            commandLine = parser.parse(csvOptions, args);
          } catch (ParseException e) {
            ioTPrinter.println("Parse error: " + e.getMessage());
            printHelpOptions(null, Constants.IMPORT_CLI_PREFIX, hf, null, csvOptions, null, false);
            System.exit(Constants.CODE_ERROR);
          }
        } else if (Constants.SQL_SUFFIXS.equalsIgnoreCase(fileType)) {
          try {
            commandLine = parser.parse(sqlOptions, args);
          } catch (ParseException e) {
            ioTPrinter.println("Parse error: " + e.getMessage());
            printHelpOptions(null, Constants.IMPORT_CLI_PREFIX, hf, null, null, sqlOptions, false);
            System.exit(Constants.CODE_ERROR);
          }
        } else {
          ioTPrinter.println(String.format("File type %s is not support", fileType));
          printHelpOptions(
              Constants.IMPORT_CLI_HEAD,
              Constants.IMPORT_CLI_PREFIX,
              hf,
              tsFileOptions,
              csvOptions,
              sqlOptions,
              true);
          System.exit(Constants.CODE_ERROR);
        }
      } else {
        ioTPrinter.println(
            String.format(
                "Invalid args: Required values for option '%s' not provided",
                Constants.FILE_TYPE_NAME));
        System.exit(Constants.CODE_ERROR);
      }
    } else {
      ioTPrinter.println(
          String.format(
              "Invalid args: Required values for option '%s' not provided",
              Constants.FILE_TYPE_NAME));
      System.exit(Constants.CODE_ERROR);
    }

    try {
      parseBasicParams(commandLine);
      String filename = commandLine.getOptionValue(Constants.FILE_ARGS);
      if (filename == null) {
        ioTPrinter.println(Constants.IMPORT_CLI_HEAD);
        printHelpOptions(
            null, Constants.IMPORT_CLI_PREFIX, hf, tsFileOptions, csvOptions, sqlOptions, true);
        System.exit(Constants.CODE_ERROR);
      }
      parseSpecialParams(commandLine);
    } catch (ArgsErrorException e) {
      ioTPrinter.println("Args error: " + e.getMessage());
      System.exit(Constants.CODE_ERROR);
    } catch (Exception e) {
      ioTPrinter.println("Encounter an error, because: " + e.getMessage());
      System.exit(Constants.CODE_ERROR);
    }
    int resultCode = importFromTargetPathAsync();
    System.exit(resultCode);
  }