/** * Parses {@code argv} based on command-line interface described by the * argument to the constructor. * <p> * This method will attempt to exit the invoking application if: * <ul> * <li>the arguments cannot be parsed * <li>the default {@code --help} behavior is invoked * <li>the default {@code --version} behavior is invoked * </ul> * <p> * In any of these cases, the parser will either terminate the JVM or throw * a {@link DocoptExitException}, depending on configuration via * {@link #withExit}. * * @param argv * the command line arguments * @return A {@code Map}, where keys are names of command-line elements, * such as "--verbose" and "<path>", and values are the parsed * values of those elements. * @throws DocoptExitException * if the application should exit and JVM termination has been * disabled via {@link #withExit} */ public Map<String, Object> parse(final String... argv) { return parse(Arrays.asList(argv)); }
/** * Parses {@code argv} based on command-line interface described by the * argument to the constructor. * <p> * This method will attempt to exit the invoking application if: * <ul> * <li>the arguments cannot be parsed * <li>the default {@code --help} behavior is invoked * <li>the default {@code --version} behavior is invoked * </ul> * <p> * In any of these cases, the parser will either terminate the JVM or throw * a {@link DocoptExitException}, depending on configuration via * {@link #withExit}. * * @param argv * the command line arguments * @return A {@code Map}, where keys are names of command-line elements, * such as "--verbose" and "<path>", and values are the parsed * values of those elements. * @throws DocoptExitException * if the application should exit and JVM termination has been * disabled via {@link #withExit} */ public Map<String, Object> parse(final String... argv) { return parse(Arrays.asList(argv)); }
.parse(args);
String doc = Resources.toString(usage, Charset.forName("UTF-8")); Docopt options = new Docopt(doc); Map<String, Object> optMap = options.parse(args);
public static void main(String[] args) { Map<String, Object> params = new Docopt(doc).parse(args); String url = (String)params.get("<url>"); CrawlerConfiguration cfg = new CrawlerConfigurationBuilder(url).withMaxParallelRequests(20).withRequestDelay(500).withLinkNormalizer(new NoAnchorLinkNormalizer(url)).build(); PageCrawler crawler = new PageCrawler(cfg); crawler.crawl(new DownloadMatchingVisitor((String)params.get("--valid-pages"), (String)params.get("--download-pages"), (String)params.get("--output-folder"))); } }
new Docopt(USAGE) .withVersion(GitRepositoryState.getRepositoryState().describe) .parse(args); String corfuConfigurationString = (String) opts.get("-c");
/** * boilerplate activity generator, to be invoked from an application's main(). * * @param args are the args passed to main */ void start(String[] args) { // Parse the options given, using docopt. Map<String, Object> opts = new Docopt(USAGE) .withVersion(GitRepositoryState.getRepositoryState().describe) .parse(args); String corfuConfigurationString = (String) opts.get("-c"); /** * Must set up a Corfu runtime before everything. */ setCorfuRuntime( getRuntimeAndConnect(corfuConfigurationString) ); /** * Obviously, this application is not doing much yet, * but you can already invoke getRuntimeAndConnect to test if you can connect to a deployed Corfu service. * * Next, invoke a class-specific activity wrapper named 'action()'. */ action(); }