Java Code Examples for org.kohsuke.args4j.CmdLineParser#setUsageWidth()

The following examples show how to use org.kohsuke.args4j.CmdLineParser#setUsageWidth() . 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: AppMain.java    From chassis with Apache License 2.0 6 votes vote down vote up
private static Arguments loadArguments(String[] args) {
    Arguments arguments = new Arguments();
    CmdLineParser parser = new CmdLineParser(arguments);
    parser.setUsageWidth(150);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println();
        parser.printUsage(System.err);
        return null;
    }
    if (arguments.help) {
        parser.printUsage(System.err);
        return null;
    }

    return arguments;
}
 
Example 2
Source File: CommandLineArgs.java    From FlowSpaceFirewall with Apache License 2.0 6 votes vote down vote up
public CommandLineArgs(String... args){
	CmdLineParser parser = new CmdLineParser(this);
	parser.setUsageWidth(80);
	try{
		parser.parseArgument(args);
		
		if(!getConfig().isFile()){
			throw new CmdLineException(parser, "--config is not a valid file.");
		}
		
		errorFree = true;
	} catch(CmdLineException e){
		System.err.println(e.getMessage());
		parser.printUsage(System.err);
	}
}
 
Example 3
Source File: ReportDiffer.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
private void parseArgs(String[] args) throws CmdLineException {
  CmdLineParser parser = new CmdLineParser(this);
  try {
    parser.parseArgument(args);
  } catch (CmdLineException e) {
    System.err.println(e.getMessage() + "\n");
    parser.setUsageWidth(120);
    parser.printUsage(System.err);
    throw new CmdLineException("Exiting...");
  }
}
 
Example 4
Source File: ConfigModule.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  // For printing errors to the caller
  bind(PrintStream.class).annotatedWith(Output.class).toInstance(System.out);
  bind(PrintStream.class).annotatedWith(Error.class).toInstance(System.err);
  CommandLineConfig config = new CommandLineConfig(out, err);
  CmdLineParser parser = new CmdLineParser(config);
  // We actually do this work in configure, since we want to bind the parsed command line
  // options at this time
  try {
    parser.parseArgument(args);
    config.validate();
    bind(ClassPath.class).toInstance(new ClassPathFactory().createFromPath(config.cp));
    bind(ReportFormat.class).toInstance(config.format);      
  } catch (CmdLineException e) {
    err.println(e.getMessage() + "\n");
    parser.setUsageWidth(120);
    parser.printUsage(err);
    err.println("Exiting...");
  }
  bind(CommandLineConfig.class).toInstance(config);
  bind(ReportOptions.class).toInstance(new ReportOptions(
      config.cyclomaticMultiplier, config.globalMultiplier, config.constructorMultiplier,
      config.maxExcellentCost, config.maxAcceptableCost, config.worstOffenderCount,
      config.maxMethodCount, config.maxLineCount, config.printDepth, config.minCost,
      config.srcFileLineUrl, config.srcFileUrl));
  bindConstant().annotatedWith(Names.named("printDepth")).to(config.printDepth);
  bind(new TypeLiteral<List<String>>() {}).toInstance(config.entryList);

  //TODO: install the appropriate language-specific module
  install(new JavaTestabilityModule(config));
}
 
Example 5
Source File: Flags.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the given command line flags, exiting the program if there are any errors or if usage
 * information was requested with the {@link #displayHelp --help} flag.
 */
static synchronized Flags parse(String[] args, FileSystem fileSystem) {
  final Flags flags = new Flags(fileSystem);
  CmdLineParser parser = new CmdLineParser(flags);
  parser.setUsageWidth(79);

  try {
    parser.parseArgument(args);
  } catch (CmdLineException e) {
    if (!flags.displayHelp) {
      System.err.println(e.getMessage());
    }
    flags.displayHelp = true;
  }

  if (flags.displayHelp) {
    System.err.println("\nUsage: dossier [options] -c CONFIG");

    System.err.println("\nwhere options include:\n");
    parser.printUsage(System.err);
  }

  if (flags.displayJsonHelp) {
    System.err.println("\nThe JSON configuration file may have the following options:\n");
    System.err.println(Config.getOptionsText(false));
  }

  if (flags.displayHelp || flags.displayJsonHelp) {
    System.exit(1);
  }

  return flags;
}
 
Example 6
Source File: DownloadAccountInfo.java    From ofx4j with Apache License 2.0 4 votes vote down vote up
public void doMain(String[] args) throws Exception {
  CmdLineParser parser = new CmdLineParser(this);
  parser.setUsageWidth(120);

  try {
    parser.parseArgument(args);

    FinancialInstitutionDataStore dataStore = new LocalResourceFIDataStore();
    FinancialInstitutionData data = null;
    for (FinancialInstitutionData item : dataStore.getInstitutionDataList()) {
      if (fid.equals(item.getFinancialInstitutionId())) {
        data = item;
        break;
      }
    }
    if (data == null) {
      exit("Unknown financial institution: " + fid);
    }

    OFXV1Connection connection = new OFXV1Connection();
    FinancialInstitution fi = new FinancialInstitutionImpl(data, connection);
    Collection<AccountProfile> profiles = fi.readAccountProfiles(username, password);
    AccountInfoResponse accountsElement = new AccountInfoResponse();
    accountsElement.setAccounts(profiles);

    AggregateMarshaller marshaller = new AggregateMarshaller();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    OFXWriter writer = new OFXV1Writer(bytes);
    ((OFXV1Writer)writer).setWriteAttributesOnNewLine(true);
    if (v2) {
      writer = new OFXV2Writer(bytes);
    }
    marshaller.marshal(accountsElement, writer);
    writer.close();
    System.out.println(bytes.toString());
    System.out.flush();

    if (out != null) {
      FileOutputStream stream = new FileOutputStream(out);
      stream.write(bytes.toByteArray());
      stream.flush();
      stream.close();
    }
  }
  catch (CmdLineException e) {
    invalidArgs(parser, e);
  }
}
 
Example 7
Source File: Worker.java    From neo4j-mazerunner with Apache License 2.0 4 votes vote down vote up
public void doMain(String[] args) throws Exception {

        CmdLineParser parser = new CmdLineParser(this);

        // if you have a wider console, you could increase the value;
        // here 80 is also the default
        parser.setUsageWidth(80);

        try {
            // parse the arguments.
            parser.parseArgument(args);

            if(sparkMaster == "" || hadoopHdfs == "")
                throw new CmdLineException(parser, "Options required: --hadoop.hdfs <url>, --spark.master <url>");

            ConfigurationLoader.getInstance().setHadoopHdfsUri(hadoopHdfs);
            ConfigurationLoader.getInstance().setSparkHost(sparkMaster);
            ConfigurationLoader.getInstance().setAppName(sparkAppName);
            ConfigurationLoader.getInstance().setExecutorMemory(sparkExecutorMemory);
            ConfigurationLoader.getInstance().setDriverHost(driverHost);
            ConfigurationLoader.getInstance().setRabbitmqNodename(rabbitMqHost);

        } catch( CmdLineException e ) {
            // if there's a problem in the command line,
            // you'll get this exception. this will report
            // an error message.
            System.err.println(e.getMessage());
            System.err.println("java -cp $CLASSPATH [<spark-config-options>] <main-class> [<mazerunner-args>]");
            // print the list of available options
            parser.printUsage(System.err);
            System.err.println();

            // print option sample. This is useful some time
            System.err.println("  Example: java -cp $CLASSPATH org.mazerunner.core.messaging.Worker"+parser.printExample(ALL));

            return;
        }

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(ConfigurationLoader.getInstance().getRabbitmqNodename());
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

        channel.basicQos(20);

        // Initialize spark context
        GraphProcessor.initializeSparkContext();

        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume(TASK_QUEUE_NAME, false, consumer);

        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

        while (true) {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            String message = new String(delivery.getBody());

            System.out.println(" [x] Received '" + message + "'");

            // Deserialize message
            Gson gson = new Gson();
            ProcessorMessage processorMessage = gson.fromJson(message, ProcessorMessage.class);

            // Run PageRank
            GraphProcessor.processEdgeList(processorMessage);

            System.out.println(" [x] Done '" + message + "'");
            channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
        }
    }
 
Example 8
Source File: CliMain.java    From btrbck with GNU General Public License v3.0 4 votes vote down vote up
private void parseCmdLine(String[] args) {
	CmdLineParser parser = new CmdLineParser(this);

	// if you have a wider console, you could increase the value;
	// here 80 is also the default
	parser.setUsageWidth(80);

	try {
		// parse the arguments.
		parser.parseArgument(args);

		if (arguments.isEmpty()) {
			throw new CmdLineException(parser, "No command given");
		}
	}
	catch (CmdLineException e) {
		// if there's a problem in the command line,
		// you'll get this exception. this will report
		// an error message.
		System.err.println("Error: " + e.getMessage());

		try {
			ByteStreams.copy(getClass().getResourceAsStream("usage.txt"),
					System.err);
		}
		catch (IOException e1) {
			throw new RuntimeException("Error while printing usage", e1);
		}

		System.err.println("\n\nOptions: ");
		// print the list of available options
		parser.printUsage(System.err);
		System.err.println();

		System.exit(1);
	}

	// initialize sudoConfig
	btrfsService.setUseSudo(sudoLocalBtrfs);
	btrfsService.setUseStrace(useStrace);
	sshService.setSudoRemoteBtrbck(sudoRemoteBtrbck);
	sshService.setSudoRemoteBtrfs(sudoRemoteBtrfs);

	// configure loglevel
	if (verbose) {
		org.apache.log4j.Logger.getRootLogger().setLevel(Level.DEBUG);
		sshService.setVerboseRemote(verbose);
	}
}