Java Code Examples for net.sourceforge.argparse4j.inf.ArgumentParser#handleError()

The following examples show how to use net.sourceforge.argparse4j.inf.ArgumentParser#handleError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdlChecker.java    From archie with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("AdlChecker")
            .defaultHelp(true)
            .description("Checks the syntax of ADL files");

    parser.addArgument("file").nargs("*")
            .help("File to calculate checksum");

    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }

    if(ns.getList("file").isEmpty()) {
        parser.printUsage();
        parser.printHelp();
    }

    validateArchetypes(ns.getList("file"));
}
 
Example 2
Source File: ImpressionsToInfluxDb.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    
	ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb")
            .defaultHelp(true)
            .description("Read Seldon impressions and send stats to influx db");
	parser.addArgument("-t", "--topic").setDefault("impressions").help("Kafka topic to read from");
	parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
	parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
	parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port");
	parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user");
	parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password");
	parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database");
	parser.addArgument("--influx-measurement-impressions").setDefault("impressions").help("Influxdb impressions measurement");
	parser.addArgument("--influx-measurement-requests").setDefault("requests").help("Influxdb requests measurement");
    
    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
        ImpressionsToInfluxDb.process(ns);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }
}
 
Example 3
Source File: PredictionsToInfluxDb.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    
	ArgumentParser parser = ArgumentParsers.newArgumentParser("PredictionsToInfluxDb")
            .defaultHelp(true)
            .description("Read Seldon predictions and send stats to influx db");
	parser.addArgument("-t", "--topic").setDefault("Predictions").help("Kafka topic to read from");
	parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
	parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
	parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port");
	parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user");
	parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password");
	parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database");
	parser.addArgument("--influx-measurement").setDefault("predictions").help("Influxdb Predictions measurement");
    
    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
        PredictionsToInfluxDb.process(ns);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }
}
 
Example 4
Source File: PredictionApi.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws IOException {
  ArgumentParser parser =
      ArgumentParsers.newFor("PredictionApi")
          .build()
          .defaultHelp(true)
          .description("Prediction API Operation");

  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser predictParser = subparsers.addParser("predict");
  predictParser.addArgument("modelId");
  predictParser.addArgument("filePath");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("predict")) {
      predict(projectId, computeRegion, ns.getString("modelId"), ns.getString("filePath"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 5
Source File: ParamsUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressFBWarnings(value = "DM_EXIT", justification = "We do expect to terminate the JVM")
static Params parseArgs(final String[] args, final ArgumentParser parser) {
    final Params params = new Params();
    try {
        parser.parseArgs(args, params);
        return params;
    } catch (final ArgumentParserException e) {
        parser.handleError(e);
    }
    System.exit(1);
    return null;
}
 
Example 6
Source File: AtomixAgent.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the command line arguments, returning an argparse4j namespace.
 *
 * @param args the arguments to parse
 * @return the namespace
 */
static Namespace parseArgs(String[] args, List<String> unknown) {
  ArgumentParser parser = createParser();
  Namespace namespace = null;
  try {
    namespace = parser.parseKnownArgs(args, unknown);
  } catch (ArgumentParserException e) {
    parser.handleError(e);
    System.exit(1);
  }
  return namespace;
}
 
Example 7
Source File: TPCHGenerator.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	// Parse and handle arguments
	ArgumentParser ap = ArgumentParsers.newArgumentParser("Distributed TPCH");
	ap.defaultHelp(true);
	ap.addArgument("-s", "--scale").setDefault(1.0).help("TPC H Scale (final Size in GB)").type(Double.class);
	ap.addArgument("-p","--parallelism").setDefault(1).help("Parallelism for program").type(Integer.class);
	ap.addArgument("-e", "--extension").setDefault(".csv").help("File extension for generated files");
	ap.addArgument("-o", "--outpath").setDefault("/tmp/").help("Output directory");
	
	Namespace ns = null;
       try {
           ns = ap.parseArgs(args);
       } catch (ArgumentParserException e) {
           ap.handleError(e);
           System.exit(1);
       }
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(ns.getInt("parallelism"));
	DistributedTPCH gen = new DistributedTPCH(env);
	gen.setScale(ns.getDouble("scale"));

	String base = ns.getString("outpath");
	String ext = ns.getString("extension");
	gen.generateParts().writeAsFormattedText(base + "parts" + ext, new TpchEntityFormatter());
	gen.generateLineItems().writeAsFormattedText(base + "lineitems" + ext, new TpchEntityFormatter());
	gen.generateOrders().writeAsFormattedText(base + "orders" + ext, new TpchEntityFormatter());
	gen.generateSuppliers().writeAsFormattedText(base + "suppliers" + ext, new TpchEntityFormatter());
	gen.generatePartSuppliers().writeAsFormattedText(base + "partsuppliers" + ext, new TpchEntityFormatter());
	gen.generateRegions().writeAsFormattedText(base + "regions" + ext, new TpchEntityFormatter());
	gen.generateNations().writeAsFormattedText(base + "nations" + ext, new TpchEntityFormatter());
	gen.generateCustomers().writeAsFormattedText(base + "customers" + ext, new TpchEntityFormatter());

	env.execute("Distributed TPCH Generator, Scale = "+gen.getScale());
}
 
Example 8
Source File: ProductInProductSetManagement.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("").build();
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser addProductParser = subparsers.addParser("add_product_to_product_set");
  addProductParser.addArgument("productSetId");
  addProductParser.addArgument("productId");

  Subparser listProductInProductSetParser = subparsers.addParser("list_products_in_product_set");
  listProductInProductSetParser.addArgument("productSetId");

  Subparser removeProductFromProductSetParser =
      subparsers.addParser("remove_product_from_product_set");
  removeProductFromProductSetParser.addArgument("productId");
  removeProductFromProductSetParser.addArgument("productSetId");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("add_product_to_product_set")) {
      addProductToProductSet(
          projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId"));
    }
    if (ns.get("command").equals("list_products_in_product_set")) {
      listProductsInProductSet(projectId, computeRegion, ns.getString("productSetId"));
    }
    if (ns.get("command").equals("remove_product_from_product_set")) {
      removeProductFromProductSet(
          projectId, computeRegion, ns.getString("productId"), ns.getString("productSetId"));
    }

  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 9
Source File: ModelApi.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
static void argsHelper(String[] args) {
  ArgumentParser parser =
      ArgumentParsers.newFor("ModelApi")
          .build()
          .defaultHelp(true)
          .description("Model API operations.");
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser createModelParser = subparsers.addParser("create_model");
  createModelParser.addArgument("datasetId");
  createModelParser.addArgument("modelName");
  createModelParser.addArgument("trainBudget");

  String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
  String computeRegion = System.getenv("REGION_NAME");

  if (projectId == null || computeRegion == null) {
    System.out.println("Set `GOOGLE_CLOUD_PROJECT` and `REGION_NAME` as specified in the README");
    System.exit(-1);
  }

  try {
    Namespace ns = parser.parseArgs(args);
    if (ns.get("command").equals("create_model")) {
      createModel(
          projectId,
          computeRegion,
          ns.getString("datasetId"),
          ns.getString("modelName"),
          ns.getString("trainBudget"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 10
Source File: SimpleConsumer.java    From kafka-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	
	ArgumentParser parser = argParser();
	
	try {
		Namespace result = parser.parseArgs(args);
		Properties configs = getConsumerConfigs(result);
		List<TopicPartition> partitions = getPartitions(result.getString("topic.partitions"));

		final SimpleConsumer<Serializable, Serializable> consumer = new SimpleConsumer<>(configs, partitions);
		consumer.run();
		
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
			
			@Override
			public void run() {
				consumer.close();
			}
		}));
		
	} catch (ArgumentParserException e) {
		if(args.length == 0)
			parser.printHelp();
		else 
			parser.handleError(e);
		System.exit(0);
	}
}
 
Example 11
Source File: ItemSimilarityProcessor.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    
	ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb")
            .defaultHelp(true)
            .description("Read Seldon impressions and send stats to influx db");
	parser.addArgument("-t", "--topic").setDefault("actions").help("Kafka topic to read from");
	parser.addArgument("-c", "--client").required(true).help("Client to run item similarity");
	parser.addArgument("-o", "--output-topic").required(true).help("Output topic");
	parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
	parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
	parser.addArgument("-w", "--window-secs").type(Integer.class).setDefault(3600*5).help("streaming window size in secs, -1 means ignore");
	parser.addArgument("-u", "--window-processed").type(Integer.class).setDefault(-1).help("streaming window size in processed count, -1 means ignore");
	parser.addArgument("--output-poll-secs").type(Integer.class).setDefault(60).help("output timer polling period in secs");
	parser.addArgument("--hashes").type(Integer.class).setDefault(100).help("number of hashes");
	parser.addArgument("-m", "--min-activity").type(Integer.class).setDefault(200).help("min activity");
	parser.addArgument("-p", "--parse-date-method").choices("json-time","json-utc","system").setDefault("json-time").help("min activity");
    
    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
        ItemSimilarityProcessor processor = new ItemSimilarityProcessor(ns);
        processor.process(ns);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }
}
 
Example 12
Source File: ConsumerRebalancer.java    From kafka-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	
	ArgumentParser parser = argParser();
	
	try {
		Namespace result = parser.parseArgs(args);
		Properties configs = getConsumerConfigs(result);
		List<String> topics = Arrays.asList(result.getString("topics").split(","));
		RecordProcessor<Serializable, Serializable> processor = getRecordProcessor(result);
		
		final ConsumerRebalancer<Serializable, Serializable> consumer = new ConsumerRebalancer<>(configs, topics);
		consumer.setProcessor(processor);
		consumer.run();
		
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
			
			@Override
			public void run() {
				consumer.close();
			}
		}));
		
	} catch (ArgumentParserException e) {
		if(args.length == 0)
			parser.printHelp();
		else 
			parser.handleError(e);
		System.exit(0);
	}
}
 
Example 13
Source File: ModelApi.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws Exception {

    ArgumentParser parser =
        ArgumentParsers.newFor("ModelApi")
            .build()
            .defaultHelp(true)
            .description("Model API operations");
    Subparsers subparsers = parser.addSubparsers().dest("command");

    Subparser createModelParser = subparsers.addParser("create_model");
    createModelParser.addArgument("datasetId");
    createModelParser.addArgument("modelName");

    Subparser listModelParser = subparsers.addParser("list_models");
    listModelParser.addArgument("filter").nargs("?").setDefault("");

    Subparser getModelParser = subparsers.addParser("get_model");
    getModelParser.addArgument("modelId");

    Subparser listModelEvaluationsParser = subparsers.addParser("list_model_evaluations");
    listModelEvaluationsParser.addArgument("modelId");
    listModelEvaluationsParser.addArgument("filter").nargs("?").setDefault("");

    Subparser getModelEvaluationParser = subparsers.addParser("get_model_evaluation");
    getModelEvaluationParser.addArgument("modelId");
    getModelEvaluationParser.addArgument("modelEvaluationId");

    Subparser deleteModelParser = subparsers.addParser("delete_model");
    deleteModelParser.addArgument("modelId");

    Subparser getOperationStatusParser = subparsers.addParser("get_operation_status");
    getOperationStatusParser.addArgument("operationFullId");

    String projectId = System.getenv("PROJECT_ID");
    String computeRegion = System.getenv("REGION_NAME");

    Namespace ns = null;
    try {
      ns = parser.parseArgs(args);
      if (ns.get("command").equals("create_model")) {
        createModel(projectId, computeRegion, ns.getString("datasetId"), ns.getString("modelName"));
      }
      if (ns.get("command").equals("list_models")) {
        listModels(projectId, computeRegion, ns.getString("filter"));
      }
      if (ns.get("command").equals("get_model")) {
        getModel(projectId, computeRegion, ns.getString("modelId"));
      }
      if (ns.get("command").equals("list_model_evaluations")) {
        listModelEvaluations(
            projectId, computeRegion, ns.getString("modelId"), ns.getString("filter"));
      }
      if (ns.get("command").equals("get_model_evaluation")) {
        getModelEvaluation(
            projectId, computeRegion, ns.getString("modelId"), ns.getString("modelEvaluationId"));
      }
      if (ns.get("command").equals("delete_model")) {
        deleteModel(projectId, computeRegion, ns.getString("modelId"));
      }
      if (ns.get("command").equals("get_operation_status")) {
        getOperationStatus(ns.getString("operationFullId"));
      }
    } catch (ArgumentParserException e) {
      parser.handleError(e);
    }
  }
 
Example 14
Source File: DatasetApi.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("").build();
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser createDatasetParser = subparsers.addParser("create_dataset");
  createDatasetParser.addArgument("datasetName");
  createDatasetParser.addArgument("source");
  createDatasetParser.addArgument("target");

  Subparser listDatasetParser = subparsers.addParser("list_datasets");
  listDatasetParser.addArgument("filter").nargs("?").setDefault("translation_dataset_metadata:*");

  Subparser getDatasetParser = subparsers.addParser("get_dataset");
  getDatasetParser.addArgument("datasetId");

  Subparser importDataParser = subparsers.addParser("import_data");
  importDataParser.addArgument("datasetId");
  importDataParser.addArgument("path");

  Subparser deleteDatasetParser = subparsers.addParser("delete_dataset");
  deleteDatasetParser.addArgument("datasetId");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("create_dataset")) {
      createDataset(
          projectId,
          computeRegion,
          ns.getString("datasetName"),
          ns.getString("source"),
          ns.getString("target"));
    }
    if (ns.get("command").equals("list_datasets")) {
      listDatasets(projectId, computeRegion, ns.getString("filter"));
    }
    if (ns.get("command").equals("get_dataset")) {
      getDataset(projectId, computeRegion, ns.getString("datasetId"));
    }
    if (ns.get("command").equals("import_data")) {
      importData(projectId, computeRegion, ns.getString("datasetId"), ns.getString("path"));
    }
    if (ns.get("command").equals("delete_dataset")) {
      deleteDataset(projectId, computeRegion, ns.getString("datasetId"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 15
Source File: KryoConsumerExample.java    From kafka-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    ArgumentParser parser = argParser();

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

        /* parse args */
        String brokerList = res.getString("bootstrap.servers");
        String topic = res.getString("topic");


        Properties consumerConfig = new Properties();
        consumerConfig.put("group.id", "my-group");
        consumerConfig.put("bootstrap.servers", brokerList);
        consumerConfig.put("auto.offset.reset", "earliest");
        consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "kafka.examples.kryo.serde.KryoDeserializer");
        consumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "kafka.examples.kryo.serde.KryoDeserializer");

        KafkaConsumer<String, Object> consumer = new KafkaConsumer<>(consumerConfig);
        consumer.subscribe(Collections.singletonList(topic));

        while (true) {
            ConsumerRecords<String, Object> records = consumer.poll(1000);
            for (ConsumerRecord<String, Object> record : records) {
                System.out.printf("Received Message topic =%s, partition =%s, offset = %d, key = %s, value = %s\n", record.topic(), record.partition(), record.offset(), record.key(), record.value());
            }

            consumer.commitSync();
        }


    } catch (ArgumentParserException e) {
        if (args.length == 0) {
            parser.printHelp();
            System.exit(0);
        } else {
            parser.handleError(e);
            System.exit(1);
        }
    }

}
 
Example 16
Source File: BasicConsumerExample.java    From kafka-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    ArgumentParser parser = argParser();

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

        /* parse args */
        String brokerList = res.getString("bootstrap.servers");
        String topic = res.getString("topic");
        String serializer = res.getString("serializer");


        Properties consumerConfig = new Properties();
        consumerConfig.put("group.id", "my-group");
        consumerConfig.put("bootstrap.servers",brokerList);
        consumerConfig.put("auto.offset.reset","earliest");
        consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer");
        consumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer");

        KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(consumerConfig);
        consumer.subscribe(Collections.singletonList(topic));

        while (true) {
            ConsumerRecords<byte[], byte[]> records = consumer.poll(1000);
            for (ConsumerRecord<byte[], byte[]> record : records) {
                System.out.printf("Received Message topic =%s, partition =%s, offset = %d, key = %s, value = %s\n", record.topic(), record.partition(), record.offset(), deserialize(record.key()), deserialize(record.value()));
            }

            consumer.commitSync();
        }

    } catch (ArgumentParserException e) {
        if (args.length == 0) {
            parser.printHelp();
            System.exit(0);
        } else {
            parser.handleError(e);
            System.exit(1);
        }
    }

}
 
Example 17
Source File: ProductManagement.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public void argsHelper(String[] args, PrintStream out) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("Product Management").build();
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser createProductParser = subparsers.addParser("create_product");
  createProductParser.addArgument("productId");
  createProductParser.addArgument("productDisplayName");
  createProductParser.addArgument("productCategory");
  createProductParser.addArgument("productDescription");
  createProductParser.addArgument("productLabels").nargs("?").setDefault("");

  subparsers.addParser("list_products");

  Subparser getProductParser = subparsers.addParser("get_product");
  getProductParser.addArgument("productId");

  Subparser updateProductLabelsParser = subparsers.addParser("update_product_labels");
  updateProductLabelsParser.addArgument("productId");
  updateProductLabelsParser.addArgument("productLabels");

  Subparser deleteProductParser = subparsers.addParser("delete_product");
  deleteProductParser.addArgument("productId");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("create_product")) {
      createProduct(
          projectId,
          computeRegion,
          ns.getString("productId"),
          ns.getString("productDisplayName"),
          ns.getString("productCategory"));
    }
    if (ns.get("command").equals("list_products")) {
      listProducts(projectId, computeRegion);
    }
    if (ns.get("command").equals("get_product")) {
      getProduct(projectId, computeRegion, ns.getString("productId"));
    }
    if (ns.get("command").equals("update_product_labels")) {
      updateProductLabels(
          projectId, computeRegion, ns.getString("productId"), ns.getString("productLabels"));
    }
    if (ns.get("command").equals("delete_product")) {
      deleteProduct(projectId, computeRegion, ns.getString("productId"));
    }
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 18
Source File: ProductSetManagement.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("Product Set Management").build();
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser createProductSetParser = subparsers.addParser("create_product_set");
  createProductSetParser.addArgument("productSetId");
  createProductSetParser.addArgument("productSetDisplayName");

  subparsers.addParser("list_product_sets");

  Subparser getProductSetParser = subparsers.addParser("get_product_set");
  getProductSetParser.addArgument("productSetId");

  Subparser deleteProductSetParser = subparsers.addParser("delete_product_set");
  deleteProductSetParser.addArgument("productSetId");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("create_product_set")) {
      createProductSet(
          projectId,
          computeRegion,
          ns.getString("productSetId"),
          ns.getString("productSetDisplayName"));
    }
    if (ns.get("command").equals("list_product_sets")) {
      listProductSets(projectId, computeRegion);
    }
    if (ns.get("command").equals("get_product_set")) {
      getProductSet(projectId, computeRegion, ns.getString("productSetId"));
    }
    if (ns.get("command").equals("delete_product_set")) {
      deleteProductSet(projectId, computeRegion, ns.getString("productSetId"));
    }

  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 19
Source File: ReferenceImageManagement.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void argsHelper(String[] args, PrintStream out) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("Reference Image Management").build();
  Subparsers subparsers = parser.addSubparsers().dest("command");

  Subparser createReferenceImageParser = subparsers.addParser("create_reference_image");
  createReferenceImageParser.addArgument("productId");
  createReferenceImageParser.addArgument("referenceImageId");
  createReferenceImageParser.addArgument("gcsUri");

  Subparser listReferenceImagesOfProductParser =
      subparsers.addParser("list_reference_images_of_product");
  listReferenceImagesOfProductParser.addArgument("productId");

  Subparser getReferenceImageParser = subparsers.addParser("get_reference_image");
  getReferenceImageParser.addArgument("productId");
  getReferenceImageParser.addArgument("referenceImageId");

  Subparser deleteReferenceImageParser = subparsers.addParser("delete_reference_image");
  deleteReferenceImageParser.addArgument("productId");
  deleteReferenceImageParser.addArgument("referenceImageId");

  String projectId = System.getenv("PROJECT_ID");
  String computeRegion = System.getenv("REGION_NAME");

  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    if (ns.get("command").equals("create_reference_image")) {
      createReferenceImage(
          projectId,
          computeRegion,
          ns.getString("productId"),
          ns.getString("referenceImageId"),
          ns.getString("gcsUri"));
    }
    if (ns.get("command").equals("list_reference_images_of_product")) {
      listReferenceImagesOfProduct(projectId, computeRegion, ns.getString("productId"));
    }
    if (ns.get("command").equals("get_reference_image")) {
      getReferenceImage(
          projectId, computeRegion, ns.getString("productId"), ns.getString("referenceImageId"));
    }
    if (ns.get("command").equals("delete_reference_image")) {
      deleteReferenceImage(
          projectId, computeRegion, ns.getString("productId"), ns.getString("referenceImageId"));
    }

  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
}
 
Example 20
Source File: Launcher.java    From minecraft-world-downloader with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parse commandline arguments.
 */
private static Namespace getArguments(String[] args) {
    ArgumentParser parser = ArgumentParsers.newFor("world-downloader.jar").build()
        .defaultHelp(true)
        .description("Download Minecraft worlds by reading chunk data from network traffic.");
    parser.addArgument("-s", "--server")
        .required(true)
        .help("The address of the remote server to connect to. Hostname or IP address (without port).");
    parser.addArgument("-p", "--port").type(Integer.class)
        .setDefault(25565)
        .help("The port of the remote server.");
    parser.addArgument("-l", "--local-port").type(Integer.class)
        .setDefault(25565)
        .help("The local port which the client has to connect to.")
        .dest("local-port");
    parser.addArgument("-o", "--output")
        .setDefault("world")
        .help("The world output directory. If the world already exists, it will attempt to merge with it.");
    parser.addArgument("-b", "--mask-bedrock").dest("mask-bedrock")
        .setDefault(false)
        .type(boolean.class)
        .help("Convert all bedrock to stone to make world locations harder to find. Currently only for 1.12.2.");
    parser.addArgument("-x", "--center-x")
        .setDefault(0)
        .type(Integer.class)
        .dest("center-x")
        .help("Center for x-coordinate. World will be offset by this coordinate so that its centered around 0.");
    parser.addArgument("-z", "--center-z")
        .setDefault(0)
        .type(Integer.class)
        .dest("center-z")
        .help("Center for z-coordinate. World will be offset by this coordinate so that its centered around 0.");
    parser.addArgument("-g", "--gui")
        .setDefault(true)
        .type(boolean.class)
        .help("Show GUI indicating which chunks have been saved.");
    parser.addArgument("-e", "--seed")
        .setDefault(0L)
        .type(Long.class)
        .help("Level seed for output file, as a long.");
    parser.addArgument("-m", "--minecraft")
        .setDefault(getDefaultPath())
        .help("Path to your Minecraft installation, used to authenticate with Mojang servers.");
    parser.addArgument("-r", "--render-distance").dest("render-distance")
        .setDefault(75)
        .type(Integer.class)
        .help("Render distance of (in chunks) of the overview map.");
    parser.addArgument("--mark-new-chunks").dest("mark-new-chunks")
        .setDefault(false)
        .type(boolean.class)
        .help("Mark new chunks in an orange outline.");
    parser.addArgument("--write-chunks").dest("write-chunks")
        .setDefault(true)
        .type(boolean.class)
        .help("Set to false to disable writing the chunks, mostly for debugging purposes.");
    parser.addArgument("-w", "--enable-world-gen").dest("enable-world-gen")
        .setDefault(true)
        .type(boolean.class)
        .help("When false, set world type to a superflat void to prevent new chunks from being added.");

    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
    } catch (ArgumentParserException ex) {
        parser.handleError(ex);
        System.exit(1);
    }
    return ns;
}