public static void printHelpInfo()

in odps-console-basic/src/main/java/com/aliyun/openservices/odps/console/utils/CommandParserUtils.java [428:483]


  public static void printHelpInfo(List<String> keywords, ExecutionContext ctx) {
    Map<String, Integer> matched = new HashMap<String, Integer>() {
    };
    List<String> allCommands = new ArrayList<String>();

    List<PluginPriorityCommand> ecList = getExtendedCommandList();

    for (PluginPriorityCommand command : ecList) {
      allCommands.add(command.getCommandName());
    }

    if (classLoader == null) {
      loadPlugins();
    }

    for (String commandName : allCommands) {
      try {
        Class<?> commandClass = getClassFromPlugin(commandName);
        Field tags_field = commandClass.getField(HELP_TAGS_FIELD);
        String[] tags = (String[]) tags_field.get(null);

        int count = 0;
        for (String tag : tags) {
          for (String keyword : keywords) {
            if (tag.equalsIgnoreCase(keyword)) {
              count++;
              break;
            }
          }
        }
        if (count != 0) {
          matched.put(commandName, count);
        }
      } catch (NoSuchFieldException e) {
        // Ignore
      } catch (IllegalAccessException e) {
        // Ignore
      }
    }

    // Print the help info of the command(s) whose tags match most keywords
    boolean found = false;
    System.out.println();
    for (int i = keywords.size(); i >= 1; i--) {
      for (Map.Entry<String, Integer> entry : matched.entrySet()) {
        if (i == entry.getValue()) {
          Class<?> commandClass = getClassFromPlugin(entry.getKey());
          found = invokePrintUsage(commandClass, System.out, ctx);
        }
      }
      if (found) {
        break;
      }
    }
    System.out.println();
  }