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


Java CmdLineParser.getRemainingArgs方法代码示例

本文整理汇总了Java中jargs.gnu.CmdLineParser.getRemainingArgs方法的典型用法代码示例。如果您正苦于以下问题:Java CmdLineParser.getRemainingArgs方法的具体用法?Java CmdLineParser.getRemainingArgs怎么用?Java CmdLineParser.getRemainingArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jargs.gnu.CmdLineParser的用法示例。


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

示例1: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
public static void main( String[] args ) {
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option date =
        parser.addOption(new ShortDateOption('d', "date"));

    try {
        parser.parse(args);
    }
    catch ( CmdLineParser.OptionException e ) {
        System.err.println(e.getMessage());
        printUsage();
        System.exit(2);
    }

    // Extract the values entered for the various options -- if the
    // options were not specified, the corresponding values will be
    // null.
    Date dateValue = (Date)parser.getOptionValue(date);

    // For testing purposes, we just print out the option values
    System.out.println("date: " + dateValue);

    // Extract the trailing command-line arguments ('a_number') in the
    // usage string above.
    String[] otherArgs = parser.getRemainingArgs();
    System.out.println("remaining args: ");
    for ( int i = 0; i < otherArgs.length; ++i ) {
        System.out.println(otherArgs[i]);
    }

    // In a real program, one would pass the option values and other
    // arguments to a function that does something more useful.

    System.exit(0);
}
 
开发者ID:ghofferek,项目名称:Suraq,代码行数:36,代码来源:CustomOptionTest.java

示例2: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
/**
 * Main client entry point for stand-alone operation.
 */
public static void main(String[] args) {
	BasicConfigurator.configure(new ConsoleAppender(
		new PatternLayout("%d [%-25t] %-5p: %m%n")));

	CmdLineParser parser = new CmdLineParser();
	CmdLineParser.Option help = parser.addBooleanOption('h', "help");
	CmdLineParser.Option output = parser.addStringOption('o', "output");
	CmdLineParser.Option iface = parser.addStringOption('i', "iface");

	try {
		parser.parse(args);
	} catch (CmdLineParser.OptionException oe) {
		System.err.println(oe.getMessage());
		usage(System.err);
		System.exit(1);
	}

	// Display help and exit if requested
	if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
		usage(System.out);
		System.exit(0);
	}

	String outputValue = (String)parser.getOptionValue(output,
			DEFAULT_OUTPUT_DIRECTORY);
	String ifaceValue = (String)parser.getOptionValue(iface);

	String[] otherArgs = parser.getRemainingArgs();
	if (otherArgs.length != 1) {
		usage(System.err);
		System.exit(1);
	}

	try {
		Client c = new Client(
			getIPv4Address(ifaceValue),
			SharedTorrent.fromFile(
				new File(otherArgs[0]),
				new File(outputValue)));

		// Set a shutdown hook that will stop the sharing/seeding and send
		// a STOPPED announce request.
		Runtime.getRuntime().addShutdownHook(
			new Thread(new ClientShutdown(c, null)));

		c.share();
		if (ClientState.ERROR.equals(c.getState())) {
			System.exit(1);
		}
	} catch (Exception e) {
		logger.error("Fatal error: {}", e.getMessage(), e);
		System.exit(2);
	}
}
 
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:58,代码来源:Client.java

示例3: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
/**
 * Main function to start a tracker.
 */
public static void main(String[] args) {
	BasicConfigurator.configure(new ConsoleAppender(
		new PatternLayout("%d [%-25t] %-5p: %m%n")));

	CmdLineParser parser = new CmdLineParser();
	CmdLineParser.Option help = parser.addBooleanOption('h', "help");
	CmdLineParser.Option port = parser.addIntegerOption('p', "port");

	try {
		parser.parse(args);
	} catch (CmdLineParser.OptionException oe) {
		System.err.println(oe.getMessage());
		usage(System.err);
		System.exit(1);
	}

	// Display help and exit if requested
	if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
		usage(System.out);
		System.exit(0);
	}

	Integer portValue = (Integer)parser.getOptionValue(port,
		Integer.valueOf(DEFAULT_TRACKER_PORT));

	String[] otherArgs = parser.getRemainingArgs();

	if (otherArgs.length > 1) {
		usage(System.err);
		System.exit(1);
	}

	// Get directory from command-line argument or default to current
	// directory
	String directory = otherArgs.length > 0
		? otherArgs[0]
		: ".";

	FilenameFilter filter = new FilenameFilter() {
		@Override
		public boolean accept(File dir, String name) {
			return name.endsWith(".torrent");
		}
	};

	try {
		Tracker t = new Tracker(new InetSocketAddress(portValue.intValue()));

		File parent = new File(directory);
		for (File f : parent.listFiles(filter)) {
			logger.info("Loading torrent from " + f.getName());
			t.announce(TrackedTorrent.load(f));
		}

		logger.info("Starting tracker with {} announced torrents...",
			t.torrents.size());
		t.start();
	} catch (Exception e) {
		logger.error("{}", e.getMessage(), e);
		System.exit(2);
	}
}
 
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:66,代码来源:Tracker.java

示例4: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
public static void main(String[] argv) throws CmdLineParser.UnknownOptionException, CmdLineParser.IllegalOptionValueException {
    Globals.setHeadless(true);

    if (argv.length == 0 || argv[0].equals("-h") || argv[0].equals("--help") || argv[0].equals("-V") || argv[0].equals("--version")) {
        CLTFactory.generalUsage();
        System.exit(0);
    }

    String cmdName = argv[0].toLowerCase();

    CmdLineParser parser = new CommandLineParser();
    if (CommandLineParserForJuicer.isJuicerCommand(cmdName)) {
        parser = new CommandLineParserForJuicer();
        HiCGlobals.useCache = false; //TODO until memory leak cleared
    }
    boolean help;
    boolean version;
    parser.parse(argv);

    if (CommandLineParserForJuicer.isJuicerCommand(cmdName)) {
        HiCGlobals.printVerboseComments = ((CommandLineParserForJuicer)parser).getVerboseOption();
        HiCGlobals.isLegacyOutputPrintingEnabled = ((CommandLineParserForJuicer) parser).getLegacyOutputOption();
        help = ((CommandLineParserForJuicer)parser).getHelpOption();
        version =  ((CommandLineParserForJuicer)parser).getVersionOption();
    }
    else {
        HiCGlobals.printVerboseComments = ((CommandLineParser)parser).getVerboseOption();
        help = ((CommandLineParser)parser).getHelpOption();
        version = ((CommandLineParser)parser).getVersionOption();
        if (((CommandLineParser)parser).getAllPearsonsOption()) {
            HiCGlobals.MAX_PEARSON_ZOOM = 1;
        }
    }
    String[] args = parser.getRemainingArgs();

    JuiceboxCLT instanceOfCLT;
    String cmd = "";
    if (args.length == 0) {
        instanceOfCLT = null;
    } else {
        cmd = args[0];
        instanceOfCLT = CLTFactory.getCLTCommand(cmd);
    }
    if (instanceOfCLT != null) {
        if (version) {
            System.out.println("Juicer tools version " + HiCGlobals.versionNum);
        }
        if (args.length == 1 || help) {
            instanceOfCLT.printUsageAndExit();
        }

        instanceOfCLT.readArguments(args, parser);
        instanceOfCLT.run();
    } else {
        throw new RuntimeException("Unknown command: " + cmd);
    }
}
 
开发者ID:theaidenlab,项目名称:Juicebox,代码行数:58,代码来源:HiCTools.java

示例5: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
/**
 * Torrent reader and creator.
 *
 * <p> You can use the {@code main()} function of this class to read or create
 * torrent files. See usage for details.</p>
 */
public static void main(String[] args) {
  BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%-5p: %m%n")));

  CmdLineParser parser = new CmdLineParser();
  CmdLineParser.Option argHelp = parser.addBooleanOption('h', "help");
  CmdLineParser.Option argAnnounce = parser.addStringOption('a', "announce");
  CmdLineParser.Option argCache = parser.addStringOption('c', "cache");
  CmdLineParser.Option argLink = parser.addBooleanOption('s', "symbolic-links");

  try {
    parser.parse(args);
  } catch (CmdLineParser.OptionException oe) {
    System.err.println(oe.getMessage());
    usage(System.err);
    System.exit(1);
  }

  // Display help and exit if requested
  if (Boolean.TRUE.equals(parser.getOptionValue(argHelp))) {
    usage(System.out);
    System.exit(0);
  }

  // For repeated announce urls
  @SuppressWarnings("unchecked")
  Vector<String> announceUrls = (Vector<String>) parser.getOptionValues(argAnnounce);
  String cache = (String) parser.getOptionValue(argCache, null);
  boolean link = (Boolean) parser.getOptionValue(argLink, false);

  File cacheFile = cache == null ? null : new File(cache);

  String[] otherArgs = parser.getRemainingArgs();

  try {
    // Process the announce URLs into URIs
    List<URI> announceUris = new ArrayList<URI>();
    for (String url : announceUrls) {
      announceUris.add(new URI(url));
    }

    // Create the announce-list as a list of lists of URIs
    // Assume all the URI's are first tier trackers
    List<List<URI>> announceList = new ArrayList<List<URI>>();
    announceList.add(announceUris);

    File source = new File(otherArgs[0]);
    if (!source.exists() || !source.canRead()) {
      throw new IllegalArgumentException("Cannot access source file or directory "
        + source.getName());
    }

    String creator = String.format("%s (ttorrent)", System.getProperty("user.name"));

    List<Torrent> torrents = TfsUtil.generateTorrentFromTfs(source, Encoding.BENCODE_BASE64, announceList, creator, cacheFile, link);
    TfsUtil.saveTorrents(new File("."), torrents);
  } catch (Exception e) {
    logger.error("{}", e.getMessage(), e);
    System.exit(2);
  }
}
 
开发者ID:cjmalloy,项目名称:torrent-fs,代码行数:67,代码来源:GenerateTfs.java

示例6: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
/**
 * Main function to start a tracker.
 */
public static void main(String[] args) {
	BasicConfigurator.configure(new ConsoleAppender(
		new PatternLayout("%d [%-25t] %-5p: %m%n")));

	CmdLineParser parser = new CmdLineParser();
	CmdLineParser.Option help = parser.addBooleanOption('h', "help");
	CmdLineParser.Option port = parser.addIntegerOption('p', "port");

	try {
		parser.parse(args);
	} catch (CmdLineParser.OptionException oe) {
		System.err.println(oe.getMessage());
		usage(System.err);
		System.exit(1);
	}

	// Display help and exit if requested
	if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
		usage(System.out);
		System.exit(0);
	}

	Integer portValue = (Integer)parser.getOptionValue(port,
		Integer.valueOf(Tracker.DEFAULT_TRACKER_PORT));

	String[] otherArgs = parser.getRemainingArgs();

	if (otherArgs.length > 1) {
		usage(System.err);
		System.exit(1);
	}

	// Get directory from command-line argument or default to current
	// directory
	String directory = otherArgs.length > 0
		? otherArgs[0]
		: ".";

	FilenameFilter filter = new FilenameFilter() {
		@Override
		public boolean accept(File dir, String name) {
			return name.endsWith(".torrent");
		}
	};

	try {
		Tracker t = new Tracker(new InetSocketAddress(portValue.intValue()));

		File parent = new File(directory);
		for (File f : parent.listFiles(filter)) {
			logger.info("Loading torrent from " + f.getName());
			t.announce(TrackedTorrent.load(f));
		}

		logger.info("Starting tracker with {} announced torrents...",
			t.getTrackedTorrents().size());
		t.start();
	} catch (Exception e) {
		logger.error("{}", e.getMessage(), e);
		System.exit(2);
	}
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:66,代码来源:TrackerMain.java

示例7: main

import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
/**
 * Main client entry point for stand-alone operation.
 */
public static void main(String[] args) {
	BasicConfigurator.configure(new ConsoleAppender(
		new PatternLayout("%d [%-25t] %-5p: %m%n")));

	CmdLineParser parser = new CmdLineParser();
	CmdLineParser.Option help = parser.addBooleanOption('h', "help");
	CmdLineParser.Option output = parser.addStringOption('o', "output");
	CmdLineParser.Option iface = parser.addStringOption('i', "iface");
	CmdLineParser.Option seedTime = parser.addIntegerOption('s', "seed");
	CmdLineParser.Option maxUpload = parser.addDoubleOption('u', "max-upload");
	CmdLineParser.Option maxDownload = parser.addDoubleOption('d', "max-download");

	try {
		parser.parse(args);
	} catch (CmdLineParser.OptionException oe) {
		System.err.println(oe.getMessage());
		usage(System.err);
		System.exit(1);
	}

	// Display help and exit if requested
	if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
		usage(System.out);
		System.exit(0);
	}

	String outputValue = (String)parser.getOptionValue(output,
		DEFAULT_OUTPUT_DIRECTORY);
	String ifaceValue = (String)parser.getOptionValue(iface);
	InterfaceName=ifaceValue;
	int seedTimeValue = (Integer)parser.getOptionValue(seedTime, -1);

	double maxDownloadRate = (Double)parser.getOptionValue(maxDownload, 0.0);
	double maxUploadRate = (Double)parser.getOptionValue(maxUpload, 0.0);

	String[] otherArgs = parser.getRemainingArgs();
	if (otherArgs.length != 1) {
		usage(System.err);
		System.exit(1);
	}

	try {
		Client c = new Client(
			getIPv4Address(ifaceValue),
			SharedTorrent.fromFile(
				new File(otherArgs[0]),
				new File(outputValue)));

		c.setMaxDownloadRate(maxDownloadRate);
		c.setMaxUploadRate(maxUploadRate);

		// Set a shutdown hook that will stop the sharing/seeding and send
		// a STOPPED announce request.
		Runtime.getRuntime().addShutdownHook(
			new Thread(new Client.ClientShutdown(c, null)));

		c.share(seedTimeValue);
		if (Client.ClientState.ERROR.equals(c.getState())) {
			System.exit(1);
		}
	} catch (Exception e) {
		logger.error("Fatal error: {}", e.getMessage(), e);
		System.exit(2);
	}
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:69,代码来源:ClientMain.java


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