当前位置: 首页>>代码示例>>Java>>正文


Java Namespace类代码示例

本文整理汇总了Java中net.sourceforge.argparse4j.inf.Namespace的典型用法代码示例。如果您正苦于以下问题:Java Namespace类的具体用法?Java Namespace怎么用?Java Namespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Namespace类属于net.sourceforge.argparse4j.inf包,在下文中一共展示了Namespace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadFromCLI

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
/**
 * Reads a configuration file from the passed CLI args
 *
 * @return Path to config file, or exception
 * @throws ConfigParseException if arguments were incorrectly specified, or nothing was passed (in which case it will print "usage" details)
 */
public static String loadFromCLI(String programName, String... args) throws ConfigParseException {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("java -jar " + programName + "-[VERSION].jar").defaultHelp(true);
    parser.addArgument("--config").metavar("/path/to/app-config.json").required(true).help("Path to configuration file");

    try {
        // parse CLI args and return config file
        Namespace cli = parser.parseArgs(args);
        return cli.getString("config");

    } catch (ArgumentParserException e) {
        // show help message and stop execution
        parser.handleError(e);
        throw new ConfigParseException(e);
    }
}
 
开发者ID:salesforce,项目名称:pyplyn,代码行数:22,代码来源:AppConfigFileLoader.java

示例2: run

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Override
protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception {
    final Path jobSpecsDir = Paths.get(applicationConfig.getJobSpecConfiguration().getDir());

    final ArrayList<String> specIds = namespace.get(JOB_SPEC_IDS_ARGNAME);

    final Map<JobSpecId, List<String>> allErrors =
            specIds.stream()
                    .map(specId -> getSpecErrors(jobSpecsDir, specId))
                    .filter(entry -> entry.getValue().size() > 0)
                    .collect(toMap(e -> e.getKey(), e -> e.getValue()));

    if (allErrors.size() > 0) {
        allErrors.forEach(this::printErrors);
        System.exit(1);
    } else System.exit(0);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:18,代码来源:ValidateSpecCommand.java

示例3: run

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Override
protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception {
    final String specId = namespace.get(SPEC_NAME_ARG);
    final Path specsDir = Paths.get(applicationConfig.getJobSpecConfiguration().getDir());
    final Path specFile = specsDir.resolve(specId).resolve(SPEC_DIR_SPEC_FILENAME);

    if (specFile.toFile().exists()) {
        final JobSpec jobSpec = readYAML(specFile, JobSpec.class);
        final JobSpecId jobSpecId = new JobSpecId(specId);
        final String jobName = new Faker().lorem().sentence(5);
        final Map<JobExpectedInputId, JsonNode> generatedInputs = generateInputs(jobSpec);
        final APIJobRequest jobRequest =
                new APIJobRequest(jobSpecId, jobName, generatedInputs);

        System.out.println(toJSON(jobRequest));
        System.exit(0);
    } else {
        System.err.println(specFile + ": No such file");
        System.exit(1);
    }
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:22,代码来源:GenerateRequestCommand.java

示例4: register

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
public void register ()
{
    execute (new Runnable() {
        public void run() {
            Main mainSignal = new Main(mContext);
            HashMap<String, Object> map = new HashMap<>();

            map.put("username", mUsername);
            map.put("command", "register");
            map.put("voice", false);

            Namespace ns = new Namespace(map);
            mainSignal.handleCommands(ns);
        }
    });
}
 
开发者ID:guardianproject,项目名称:haven,代码行数:17,代码来源:SignalSender.java

示例5: verify

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
public void verify (final String verificationCode)
{
    execute (new Runnable() {
        public void run() {
            Main mainSignal = new Main(mContext);
            HashMap<String, Object> map = new HashMap<>();

            map.put("username", mUsername);
            map.put("command", "verify");
            map.put("verificationCode", verificationCode);

            Namespace ns = new Namespace(map);
            mainSignal.handleCommands(ns);
        }
    });
}
 
开发者ID:guardianproject,项目名称:haven,代码行数:17,代码来源:SignalSender.java

示例6: sendMessage

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
public void sendMessage (final ArrayList<String> recipients, final String message, final String attachment)
{
    execute (new Runnable() {
        public void run() {
            Main mainSignal = new Main(mContext);
            HashMap<String, Object> map = new HashMap<>();

            map.put("username", mUsername);
            map.put("endsession",false);
            map.put("recipient", recipients);
            map.put("command", "send");
            map.put("message", message);

            if (attachment != null)
            {
                ArrayList<String> attachments = new ArrayList<>();
                attachments.add(attachment);
                map.put("attachment",attachments);
            }

            Namespace ns = new Namespace(map);
            mainSignal.handleCommands(ns);
        }
    });
}
 
开发者ID:guardianproject,项目名称:haven,代码行数:26,代码来源:SignalSender.java

示例7: createConsumer

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
private static KafkaConsumer<String, String> createConsumer(Namespace parsedArgs) {
    String consumerGroup = parsedArgs.getString("consumerGroup");
    String brokerList = parsedArgs.getString("brokerList");
    Integer numMessagesPerTransaction = parsedArgs.getInt("messagesPerTransaction");

    Properties props = new Properties();

    props.put(ConsumerConfig.GROUP_ID_CONFIG, consumerGroup);
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
    props.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, "read_committed");
    props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, numMessagesPerTransaction.toString());
    props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
    props.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "10000");
    props.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, "3000");
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
            "org.apache.kafka.common.serialization.StringDeserializer");
    props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
            "org.apache.kafka.common.serialization.StringDeserializer");

    return new KafkaConsumer<>(props);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:23,代码来源:TransactionalMessageCopier.java

示例8: runTool

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
private static void runTool(final Namespace cmdResult) {
    try {
        final File inFile = new File(cmdResult.getString("infile"));
        final File outFile = new File(cmdResult.getString("outfile"));

        runToolOnfiles(cmdResult, inFile, outFile);
    }
    // TODO PEF-61 add logging
    catch (final UnsupportedFileFormatException uffe) {
        System.err.println(uffe.getMessage());
    }
    catch (final InvalidKeyException ike) {
        System.err.println("key should be a 16-byte hexadecimal number (128-bit)");
    }
    catch (final IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:19,代码来源:CLTool.java

示例9: run

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
private void run(String... args) throws Exception {
    Namespace namespace;
    try {
        namespace = argumentParser.parseArgs(args);
    } catch (ArgumentParserException e) {
        argumentParser.handleError(e);
        return;
    }

    List<String> urls = namespace.getList(urlKey);

    try {
        Set<HttpUrl> allUrls = argResolver.getAllUrls(urls);
        if (allUrls.isEmpty())
            LOG.info("No playlists found! Check your args: " + Arrays.toString(args));

        for (HttpUrl url : allUrls)
            getHandler(url).join();
    } catch (Throwable t) {
        LOG.info("Error {}: {}", t.getClass().getSimpleName(), t.getMessage());
        LOG.debug("Detailed error output", t);
    } finally {
        theClosener.close();
    }
}
 
开发者ID:TheGoodlike13,项目名称:hls-downloader,代码行数:26,代码来源:HlsDownloaderLauncher.java

示例10: run

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Override
protected void run(Bootstrap<SamConfiguration> bootstrap, Namespace namespace, SamConfiguration configuration) throws Exception {

  final OAuth2Service service = new OAuth2Service(configuration.getOAuthConfiguration());
  final Command command = namespace.get("subcommand");
  switch (command) {
    case create:
      create(namespace.getString("subject"), service, configuration);
      break;
    case verify:
      verify(namespace.getString("jwt"), service, configuration);
      break;
    case sign:
      sign(namespace.getString("claims"), service, configuration);
      break;
    default:
      throw new IllegalStateException("Unknown command");
  }
}
 
开发者ID:atgse,项目名称:sam,代码行数:20,代码来源:OAuth2Command.java

示例11: run

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Override
protected void run(Environment environment, Namespace namespace, SamConfiguration configuration) throws Exception {

  final MongoDatabase database = configuration.getDbConnectionFactory().getDatabase(environment.lifecycle());

  final MongoCollection<Document> servers = database.getCollection(Collections.SERVERS);
  servers.drop();

  final MongoCollection<Document> applications = database.getCollection(Collections.APPLICATIONS);
  applications.drop();

  final MongoCollection<Document> groups = database.getCollection(Collections.GROUPS);
  groups.drop();

  final MongoCollection<Document> assets = database.getCollection(Collections.ASSETS);
  assets.drop();

  // Add indexes
  new CreateDatabaseCommand(application).run(environment, namespace, configuration);

  createServers(servers);
  createApplications(applications);
  createGroups(groups);
  createAssets(assets);
}
 
开发者ID:atgse,项目名称:sam,代码行数:26,代码来源:AddTestdataCommand.java

示例12: testCreate

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Test
public void testCreate() throws Exception {

  final String subject = "test-user";

  final Namespace args = new Namespace(ImmutableMap.of(
    "subcommand", Command.create,
    "subject", "test-user")
  );

  final OAuth2Command command = new OAuth2Command();
  command.run(null, args, configuration);

  final String jwt = getSystemOut().split(": ")[1];
  final Map<String, Object> claims = oAuth2Service.verify(jwt);
  Assert.assertEquals(subject, claims.get("sub"));
}
 
开发者ID:atgse,项目名称:sam,代码行数:18,代码来源:OAuth2CommandTest.java

示例13: testVerify

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Test
public void testVerify() throws Exception {

  final String subject = "test-user";
  final OAuth2IdToken jwt = oAuth2Service.createIdToken(subject, Optional.empty());

  final Namespace args = new Namespace(ImmutableMap.of(
    "subcommand", Command.verify,
    "jwt", jwt.token
  ));

  final OAuth2Command command = new OAuth2Command();
  command.run(null, args, configuration);

  final String claims = getSystemOut().split("\n")[1];
  Assert.assertTrue(claims.contains("sub=" + subject));
}
 
开发者ID:atgse,项目名称:sam,代码行数:18,代码来源:OAuth2CommandTest.java

示例14: testSign

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Test
public void testSign() throws Exception {

  final String subject = "test-user";
  final String roles = "edit admin";

  final Namespace args = new Namespace(ImmutableMap.of(
    "subcommand", Command.sign,
    "claims", "sub=test-user,scope=edit admin"
  ));

  final OAuth2Command command = new OAuth2Command();
  command.run(null, args, configuration);

  final String jwt = getSystemOut().split(": ")[1];
  final Map<String, Object> claims = oAuth2Service.verify(jwt);
  Assert.assertEquals(roles, claims.get("scope"));
  Assert.assertEquals(subject, claims.get("sub"));
}
 
开发者ID:atgse,项目名称:sam,代码行数:20,代码来源:OAuth2CommandTest.java

示例15: testSignWithExpiry

import net.sourceforge.argparse4j.inf.Namespace; //导入依赖的package包/类
@Test
public void testSignWithExpiry() throws Exception {

  final String subject = "test-user";
  final String roles = "edit admin";
  final long expiry = System.currentTimeMillis() + 60*1000;

  final Namespace args = new Namespace(ImmutableMap.of(
    "subcommand", Command.sign,
    "claims", "sub=" + subject + ",scope=" + roles + ",exp=" + expiry
  ));

  final OAuth2Command command = new OAuth2Command();
  command.run(null, args, configuration);

  final String jwt = getSystemOut().split(": ")[1];
  final Map<String, Object> claims = oAuth2Service.verify(jwt);
  Assert.assertEquals(expiry, claims.get("exp"));
  Assert.assertEquals(roles, claims.get("scope"));
  Assert.assertEquals(subject, claims.get("sub"));
}
 
开发者ID:atgse,项目名称:sam,代码行数:22,代码来源:OAuth2CommandTest.java


注:本文中的net.sourceforge.argparse4j.inf.Namespace类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。