Java源码示例:org.kohsuke.args4j.Option

示例1
@Option(name = "-agent", usage = "user agent info, format:'name,email,website'", required = false)
public void setUserAgent(String agentNameWebsiteEmailString) {
    if (isCommonCrawl()) {
        throw new RuntimeException("user agent not used in common crawl mode");
    }
    String fields[] = agentNameWebsiteEmailString.split(",", 4);
    if (fields.length != 3) {
        throw new RuntimeException(
                "    Invalid format for user agent (expected 'name,email,website'): "
                        + agentNameWebsiteEmailString);
    }
    String agentName = fields[0];
    String agentEmail = fields[1];
    String agentWebSite = fields[2];
    if (!(agentEmail.contains("@"))) {
        throw new RuntimeException("Invalid email address for user agent: " + agentEmail);
    }
    if (!(agentWebSite.startsWith("http"))) {
        throw new RuntimeException("Invalid web site URL for user agent: " + agentWebSite);
    }
    setUserAgent(new UserAgent(agentName, agentEmail, agentWebSite));
}
 
示例2
@Option(
  name = "--strict",
  usage = "Whether to run all type checking passes before generating any documentation"
)
private void setStrict(boolean strict) {
  jsonConfig.addProperty("strict", strict);
}
 
示例3
private ExitCode runLegacyFixScript(CommandRunnerParams params, ImmutableList<String> scriptPath)
    throws IOException, InterruptedException {
  ProcessExecutor processExecutor =
      new DefaultProcessExecutor(getExecutionContext().getConsole());
  ProcessExecutorParams processParams =
      ProcessExecutorParams.builder()
          .addAllCommand(scriptPath)
          .setEnvironment(params.getEnvironment())
          .setDirectory(params.getCells().getRootCell().getFilesystem().getRootPath().getPath())
          .build();
  int code =
      processExecutor
          .launchAndExecute(
              processParams,
              EnumSet.of(
                  ProcessExecutor.Option.PRINT_STD_ERR, ProcessExecutor.Option.PRINT_STD_OUT),
              Optional.empty(),
              Optional.empty(),
              Optional.empty())
          .getExitCode();
  return ExitCode.map(code);
}
 
示例4
/** @return a map that maps all options names to their {@link GoalRequirements}. */
public Map<String, GoalRequirements> getOptionNameToGoalRequirementMap() {
	Map<String, GoalRequirements> nameFieldMap = new HashMap<>();
	Field[] fields = this.options.getClass().getDeclaredFields();
	for (Field field : fields) {
		Option option = field.getDeclaredAnnotation(Option.class);
		GoalRequirements goalRequirements = field.getDeclaredAnnotation(GoalRequirements.class);
		if (field.canAccess(this.options) && option != null && goalRequirements != null) {
			nameFieldMap.put(option.name(), goalRequirements);
		}
	}
	return nameFieldMap;
}
 
示例5
@Option(
    name = GlobalCliOptions.CONFIG_LONG_ARG,
    aliases = {"-c"},
    usage = "Override .buckconfig option",
    metaVar = "section.option=value")
void addConfigOverride(String configOverride) {
  saveConfigOptionInOverrides(configOverride);
}
 
示例6
@Option(
  name = "--custom_page",
  usage =
      "Defines a markdown file to include with the generated documentation. Each page "
          + "should be defined as $name:$path, where $name is the desired page title and $path "
          + "is the path to the actual file"
)
private void addCustomPage(String spec) {
  List<String> parts = Splitter.on(':').limit(2).splitToList(spec);
  JsonObject page = new JsonObject();
  page.addProperty("name", parts.get(0));
  page.addProperty("path", parts.get(1));
  addToArray("customPages", page);
}
 
示例7
private Map<Integer, String> getRackAssignment(ZkUtils zkUtils) {
    List<Broker> brokers = JavaConversions.seqAsJavaList(zkUtils.getAllBrokersInCluster());
    Map<Integer, String> rackAssignment = Maps.newHashMap();
    if (!disableRackAwareness) {
        for (Broker broker : brokers) {
            scala.Option<String> rack = broker.rack();
            if (rack.isDefined()) {
                rackAssignment.put(broker.id(), rack.get());
            }
        }
    }
    return rackAssignment;
}
 
示例8
@Option(name = "-lib", usage = "specifies a path to search for jars and classes", metaVar = "<path>")
private void setLib(String s) {
    String[] files = s.split(System.getProperty("path.separator"));
    for (int i = 0; i < files.length; i++) {
        lib.add(new File(files[i]));
    }
}
 
示例9
@Option(
  name = "--type_filter",
  usage =
      "Regular expression for types that should be excluded from generated documentation,"
          + " even if found in the type graph"
)
private void addTypeFilter(String filter) {
  addToArray("typeFilters", filter);
}
 
示例10
@Option(
  name = "--source_url_template",
  usage =
      "Template to use when generating links to source files; refer to --help_json for"
          + " more information."
)
private void setSourceUrlTemplate(String template) {
  jsonConfig.addProperty("sourceUrlTemplate", template);
}
 
示例11
@Option(
    name = GlobalCliOptions.CONFIG_FILE_LONG_ARG,
    usage = "Override options in .buckconfig using a file parameter",
    metaVar = "PATH")
void addConfigFile(String filePath) {
  configOverrides.add(filePath);
}
 
示例12
/**
 * Helper method to print usage at the command line interface.
 */
private static void printUsage() {
  System.out.println("Usage: DictionaryTORawIndexConverter");
  for (Field field : DictionaryToRawIndexConverter.class.getDeclaredFields()) {

    if (field.isAnnotationPresent(Option.class)) {
      Option option = field.getAnnotation(Option.class);

      System.out
          .println(String.format("\t%-15s: %s (required=%s)", option.name(), option.usage(), option.required()));
    }
  }
}
 
示例13
public void printUsage() {
  System.out.println("Usage: " + this.getName());

  for (Field f : this.getClass().getDeclaredFields()) {
    if (f.isAnnotationPresent(Option.class)) {
      Option option = f.getAnnotation(Option.class);

      System.out.println(String
          .format("\t%-25s %-30s: %s (required=%s)", option.name(), option.metaVar(), option.usage(),
              option.required()));
    }
  }
  printExamples();
}
 
示例14
@Option(
  name = "--help_json",
  usage = "Print detailed usage information on the JSON configuration file format, then exit"
)
private void setDisplayJsonHelp(boolean help) {
  this.displayJsonHelp = help;
}
 
示例15
@Option(
  name = "--config",
  aliases = "-c",
  metaVar = "CONFIG",
  usage =
      "Path to the JSON configuration file to use. If specified, all other configuration "
          + "flags will be ignored"
)
private void setConfigPath(String path) {
  config = fileSystem.getPath(path).toAbsolutePath().normalize();
  checkArgument(Files.exists(config), "Path does not exist: %s", config);
  checkArgument(Files.isReadable(config), "Path is not readable: %s", config);
}
 
示例16
@Option(
  name = "--environment",
  metaVar = "ENV",
  usage =
      "Sets the target script environment."
          + " Must be one of {BROWSER, NODE}; defaults to BROWSER"
)
private void setEnvironment(Environment env) {
  jsonConfig.addProperty("environment", env.name());
}
 
示例17
@Option(
  name = "--num_threads",
  usage =
      "The number of threads to use for rendering. Defaults to 2 times the number of "
          + "available processors"
)
private void setNumThreads(int n) {
  checkArgument(n >= 1, "invalid number of flags: %s", n);
  this.numThreads = n;
}
 
示例18
@Option(
  name = "--closure_library_dir",
  metaVar = "PATH",
  usage =
      "Sets the path to the Closure library's root directory. When provided, Closure files"
          + " will automatically be added as sources based on the goog.require calls in --source"
          + " files. Refer to --help_json for more information"
)
private void setClosureLibraryDir(String path) {
  this.jsonConfig.addProperty("closureLibraryDir", path);
}
 
示例19
@Option(
  name = "--closure_dep_file",
  metaVar = "PATH",
  depends = "--closure_library_dir",
  usage =
      "Defines a file to parse for goog.addDependency calls. This requires also providing"
          + " --closure_library_dir"
)
private void addClosureDepFile(String path) {
  addToArray("closureDepFiles", path);
}
 
示例20
@Option(
  name = "--source",
  metaVar = "PATH",
  usage =
      "Defines the path to a file to extract API documentation from, or a directory of"
          + " such files"
)
private void addSource(String path) {
  addToArray("sources", path);
}
 
示例21
@Option(
  name = "--module",
  metaVar = "PATH",
  usage =
      "Defines the path to a CommonJS module to extract API documentation from, or a"
          + " directory of such files"
)
private void addModule(String path) {
  addToArray("modules", path);
}
 
示例22
@Option(
  name = "--extern",
  metaVar = "PATH",
  usage =
      "Defines the path to a file that provides extern definitions, or a directory of"
          + " such files."
)
private void addExtern(String path) {
  addToArray("externs", path);
}
 
示例23
@Option(
  name = "--extern_module",
  metaVar = "PATH",
  usage =
      "Defines the path to a file that provides extern definitions for CommonJS modules, "
          + "or a directory of such files."
)
private void addExternModule(String path) {
  addToArray("externModules", path);
}
 
示例24
@Option(
  name = "--exclude",
  metaVar = "PATH",
  usage =
      "Defines the path to a file or directory of files that should be excluded from"
          + " processing."
)
private void addExclude(String path) {
  addToArray("excludes", path);
}
 
示例25
@Option(
  name = "--output",
  metaVar = "PATH",
  usage = "Sets the path to the output directory, or a .zip file to generate the output in"
)
private void setOutput(String path) {
  jsonConfig.addProperty("output", path);
}
 
示例26
@Option(
  name = "--readme",
  metaVar = "PATH",
  usage = "Sets the path to a markdown file to include as a readme on the main landing page"
)
private void setReadme(String path) {
  jsonConfig.addProperty("readme", path);
}
 
示例27
@Option(name = "-singledomain", usage = "only fetch URLs within this domain (and its sub-domains)", required = false)
public void setSingleDomain(String singleDomain) {
    _singleDomain = singleDomain;
}
 
示例28
@Option(name = "-forcecrawldelay", usage = "use this crawl delay (ms) even if robots.txt provides something else", required = false)
public void setForceCrawlDelay(long forceCrawlDelay) {
    _forceCrawlDelay = forceCrawlDelay;
}
 
示例29
@Option(name = "-maxcontentsize", usage = "maximum content size", required = false)
public void setMaxContentSize(int maxContentSize) {
    _maxContentSize = maxContentSize;
}
 
示例30
@Option(name = "-commoncrawl", usage = "crawl id for CommonCrawl.org dataset", required = false)
public void setCommonCrawlId(String commonCrawlId) {
    _commonCrawlId = commonCrawlId;
}