net.sourceforge.argparse4j.inf.Namespace类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中net.sourceforge.argparse4j.inf.Namespace类的一些代码示例,展示了Namespace类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Namespace类的具体详情如下:
包路径:net.sourceforge.argparse4j.inf.Namespace
类名称:Namespace

Namespace介绍

[英]This class holds attributes added by ArgumentParser#parseArgs(String[]).

It is just a wrapper of Map object which stores actual attributes. Map object can be retrieved using #getAttrs(). This class provides several shortcut methods to get attribute values. #toString() provides nice textual representation of stored attributes.
[中]此类保存ArgumentParser#parseArgs(字符串[])添加的属性。
它只是一个Map对象的包装器,用于存储实际属性。可以使用#getAttrs()检索映射对象。此类提供了几种获取属性值的快捷方式方法#toString()为存储的属性提供了良好的文本表示。

代码示例

代码示例来源:origin: spotify/helios

protected FastForwardConfig ffwdConfig(final Namespace options) {
  if (!options.getBoolean(ffwdEnabled.getDest())) {
   return null;
  }

  return new FastForwardConfig(
    Optional.ofNullable(options.getString(ffwdAddress.getDest())),
    options.getInt(ffwdInterval.getDest()),
    options.getString(ffwdMetricKey.getDest()));
 }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
public void run(Namespace namespace, Liquibase liquibase) throws Exception {
  final String tag = namespace.getString("tag");
  final Integer count = namespace.getInt("count");
  final Date date = namespace.get("date");
  final boolean dryRun = namespace.getBoolean("dry-run") == null ? false : namespace.getBoolean("dry-run");
  final String context = getContext(namespace);
  if (Stream.of(tag, count, date).filter(Objects::nonNull).count() != 1) {
    throw new IllegalArgumentException("Must specify either a count, a tag, or a date.");
  }
  if (count != null) {
    if (dryRun) {
      liquibase.rollback(count, context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.rollback(count, context);
    }
  } else if (tag != null) {
    if (dryRun) {
      liquibase.rollback(tag, context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.rollback(tag, context);
    }
  } else {
    if (dryRun) {
      liquibase.rollback(date, context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.rollback(date, context);
    }
  }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
  protected void run(Bootstrap<HelloWorldConfiguration> bootstrap,
            Namespace namespace,
            HelloWorldConfiguration configuration) throws Exception {
    final Template template = configuration.buildTemplate();

    if (namespace.getBoolean("include-default")) {
      LOGGER.info("DEFAULT => {}", template.render(Optional.empty()));
    }

    for (String name : namespace.<String>getList("names")) {
      for (int i = 0; i < 1000; i++) {
        LOGGER.info("{} => {}", name, template.render(Optional.of(name)));
        Thread.sleep(1000);
      }
    }
  }
}

代码示例来源:origin: SeldonIO/seldon-server

public ItemSimilarityProcessor(final Namespace ns)
{
  this.windowSecs = ns.getInt("window_secs");
  this.windowProcessed = ns.getInt("window_processed");
  this.outputTopic = ns.getString("output_topic");
  this.kafkaServers = ns.getString("kafka");
  System.out.println(ns);
  this.streamJaccard = new StreamingJaccardSimilarity(windowSecs, ns.getInt("hashes"), ns.getInt("min_activity"));
  //createOutputSimilaritiesTimer(ns);
}

代码示例来源:origin: spotify/helios

public LoggingConfig getLoggingConfig() {
 return new LoggingConfig(options.getInt(verboseArg.getDest()),
   options.getBoolean(syslogArg.getDest()),
   (File) options.get(logconfigArg.getDest()),
   options.getBoolean(noLogSetupArg.getDest()));
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public static void main(String... args) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("SynthesizeFile").build()
    .defaultHelp(true)
    .description("Synthesize a text file or ssml file.");
  MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
  group.addArgument("--text").help("The text file from which to synthesize speech.");
  group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");

  try {
   Namespace namespace = parser.parseArgs(args);

   if (namespace.get("text") != null) {
    synthesizeTextFile(namespace.getString("text"));
   } else {
    synthesizeSsmlFile(namespace.getString("ssml"));
   }
  } catch (ArgumentParserException e) {
   parser.handleError(e);
  }
 }
}

代码示例来源:origin: spotify/helios

public String getSentryDsn() {
 return options.getString(sentryDsnArg.getDest());
}

代码示例来源:origin: spotify/helios

@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out,
    final boolean json, final BufferedReader stdin)
  throws ExecutionException, InterruptedException {
 final String name = options.getString(nameArg.getDest());
 final boolean full = options.getBoolean(fullArg.getDest());
 return run0(client, out, json, name, full);
}

代码示例来源:origin: atomix/atomix

final List<File> configFiles = namespace.getList("config");
final String memberId = namespace.getString("member");
final Address address = namespace.get("address");
final String host = namespace.getString("host");
final String rack = namespace.getString("rack");
final String zone = namespace.getString("zone");
final List<NodeConfig> bootstrap = namespace.getList("bootstrap");
final boolean multicastEnabled = namespace.getBoolean("multicast");
final String multicastGroup = namespace.get("multicast_group");
final Integer multicastPort = namespace.get("multicast_port");
System.setProperty("atomix.data", namespace.getString("data_dir"));

代码示例来源:origin: spotify/helios

final boolean json, final BufferedReader stdin)
 throws ExecutionException, InterruptedException {
final String jobIdString = options.getString(jobArg.getDest());
final String hostPattern = options.getString(hostArg.getDest());
final boolean full = options.getBoolean(fullArg.getDest());
 String domainsSwitchString = "";
 final List<String> domains = options.get("domains");
 if (domains.size() > 0) {
  domainsSwitchString = "-d " + Joiner.on(",").join(domains);

代码示例来源:origin: dropwizard/dropwizard

@Override
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public void run(Namespace namespace, Liquibase liquibase) throws Exception {
  final String context = getContext(namespace);
  final Integer count = namespace.getInt("count");
  final boolean dryRun = namespace.getBoolean("dry-run") == null ? false : namespace.getBoolean("dry-run");
  if (count != null) {
    if (dryRun) {
      liquibase.update(count, context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.update(count, context);
    }
  } else {
    if (dryRun) {
      liquibase.update(context, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    } else {
      liquibase.update(context);
    }
  }
}

代码示例来源:origin: linkedin/kafka-monitor

props.put(ProduceServiceConfig.ZOOKEEPER_CONNECT_CONFIG, res.getString("zkConnect"));
props.put(ProduceServiceConfig.BOOTSTRAP_SERVERS_CONFIG, res.getString("brokerList"));
if (res.getString("producerClassName") != null)
 props.put(ProduceServiceConfig.PRODUCER_CLASS_CONFIG, res.getString("producerClassName"));
if (res.getString("topic") != null)
 props.put(ProduceServiceConfig.TOPIC_CONFIG, res.getString("topic"));
if (res.getString("producerId") != null)
 props.put(ProduceServiceConfig.PRODUCER_ID_CONFIG, res.getString("producerId"));
if (res.getString("recordDelayMs") != null)
 props.put(ProduceServiceConfig.PRODUCE_RECORD_DELAY_MS_CONFIG, res.getString("recordDelayMs"));
if (res.getString("recordSize") != null)
 props.put(ProduceServiceConfig.PRODUCE_RECORD_SIZE_BYTE_CONFIG, res.getString("recordSize"));
if (res.getString("producerConfig") != null)
 props.put(ProduceServiceConfig.PRODUCER_PROPS_CONFIG, Utils.loadProps(res.getString("producerConfig")));
if (res.getString("consumerConfig") != null)
 props.put(ConsumeServiceConfig.CONSUMER_PROPS_CONFIG, Utils.loadProps(res.getString("consumerConfig")));
if (res.getString("consumerClassName") != null)
 props.put(ConsumeServiceConfig.CONSUMER_CLASS_CONFIG, res.getString("consumerClassName"));
if (res.getString("latencyPercentileMaxMs") != null)
 props.put(ConsumeServiceConfig.LATENCY_PERCENTILE_MAX_MS_CONFIG, res.getString("latencyPercentileMaxMs"));
if (res.getString("latencyPercentileGranularityMs") != null)
 props.put(ConsumeServiceConfig.LATENCY_PERCENTILE_GRANULARITY_MS_CONFIG, res.getString("latencyPercentileGranularityMs"));
if (res.getBoolean("autoTopicCreationEnabled") != null)
 props.put(TopicManagementServiceConfig.TOPIC_CREATION_ENABLED_CONFIG, res.getBoolean("autoTopicCreationEnabled"));
if (res.getInt("replicationFactor") != null)
 props.put(TopicManagementServiceConfig.TOPIC_REPLICATION_FACTOR_CONFIG, res.getInt("replicationFactor"));
if (res.getInt("rebalanceMs") != null)

代码示例来源:origin: dropwizard/dropwizard

@Override
  public void run(Namespace namespace, Liquibase liquibase) throws Exception {
    final AbstractLiquibaseCommand<T> subcommand =
      requireNonNull(subcommands.get(namespace.getString(COMMAND_NAME_ATTR)), "Unable find the command");
    subcommand.run(namespace, liquibase);
  }
}

代码示例来源:origin: spotify/helios

@Override
 protected int runWithJob(final Namespace options, final HeliosClient client,
              final PrintStream out, final boolean json, final Job job,
              final BufferedReader stdin)
   throws ExecutionException, InterruptedException, IOException {
  final JobId jobId = job.getId();
  final List<String> hosts = options.getList(hostsArg.getDest());

  final Deployment deployment = new Deployment.Builder()
    .setGoal(Goal.START)
    .setJobId(jobId)
    .build();

  if (!json) {
   out.printf("Starting %s on %s%n", jobId, hosts);
  }

  return Utils.setGoalOnHosts(client, out, json, hosts, deployment,
    options.getString(tokenArg.getDest()));
 }
}

代码示例来源:origin: dropwizard/dropwizard

if (isTrue(namespace.getBoolean("columns"))) {
  compareTypes.add(Column.class);
if (isTrue(namespace.getBoolean("data"))) {
  compareTypes.add(Data.class);
if (isTrue(namespace.getBoolean("foreign-keys"))) {
  compareTypes.add(ForeignKey.class);
if (isTrue(namespace.getBoolean("indexes"))) {
  compareTypes.add(Index.class);
if (isTrue(namespace.getBoolean("primary-keys"))) {
  compareTypes.add(PrimaryKey.class);
if (isTrue(namespace.getBoolean("sequences"))) {
  compareTypes.add(Sequence.class);
if (isTrue(namespace.getBoolean("tables"))) {
  compareTypes.add(Table.class);
if (isTrue(namespace.getBoolean("unique-constraints"))) {
  compareTypes.add(UniqueConstraint.class);
if (isTrue(namespace.getBoolean("views"))) {
  compareTypes.add(View.class);
final String filename = namespace.getString("output");
if (filename != null) {

代码示例来源:origin: lenskit/lenskit

File getOutputFile() {
    return options.get("output_file");
  }
}

代码示例来源:origin: AsamK/signal-cli

@Override
  public int handleCommand(final Namespace ns, final Manager m) {
    if (!m.isRegistered()) {
      System.err.println("User is not registered.");
      return 1;
    }
    if (ns.get("number") == null) {
      for (Map.Entry<String, List<JsonIdentityKeyStore.Identity>> keys : m.getIdentities().entrySet()) {
        for (JsonIdentityKeyStore.Identity id : keys.getValue()) {
          printIdentityFingerprint(m, keys.getKey(), id);
        }
      }
    } else {
      String number = ns.getString("number");
      for (JsonIdentityKeyStore.Identity id : m.getIdentities(number)) {
        printIdentityFingerprint(m, number, id);
      }
    }
    return 0;
  }
}

代码示例来源:origin: spotify/helios

public boolean getZooKeeperEnableAcls() {
 return options.getBoolean(zooKeeperEnableAcls.getDest());
}

代码示例来源:origin: dropwizard/dropwizard

private String getContext(Namespace namespace) {
    final List<Object> contexts = namespace.getList("contexts");
    if (contexts == null) {
      return "";
    }
    return contexts.stream()
        .map(Object::toString)
        .collect(Collectors.joining(","));
  }
}

代码示例来源:origin: bazaarvoice/jolt

/**
 *
 * @param ns Namespace which contains parsed commandline arguments
 * @return true if the sort was successful, false if an error occurred
 */
@Override
public boolean process( Namespace ns ) {
  File file = ns.get( "input" );
  Object jsonObject = JoltCliUtilities.readJsonInput( file, SUPPRESS_OUTPUT );
  if ( jsonObject == null ) {
    return false;
  }
  Sortr sortr = new Sortr();
  Object output = sortr.transform( jsonObject );
  Boolean uglyPrint = ns.getBoolean( "u" );
  return JoltCliUtilities.printJsonObject( output, uglyPrint, SUPPRESS_OUTPUT );
}

相关文章