/** * 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(); }
/** * Constructs an argument parser from a POSIX-style help message. * * @param doc * a POSIX-style help message * @throws DocoptLanguageError * if the help message is malformed * @see Docopt */ public Docopt(final String doc) { this.doc = doc; final List<String> usageSections = parseSection("usage:", doc); if (usageSections.size() == 0) { throw new DocoptLanguageError( "\"usage:\" (case-insensitive) not found."); } if (usageSections.size() > 1) { throw new DocoptLanguageError( "More than one \"usage:\" (case-insensitive)."); } usage = usageSections.get(0); options = parseDefaults(doc); pattern = parsePattern(formalUsage(usage), options); }
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"))); } }
/** * 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)); }
final List<? extends Pattern> u = parseExpr(tokens, options); return parseLong(tokens, options); return parseShorts(tokens, options);
private static Required parsePattern(final String source, final List<Option> options) { final Tokens tokens = Tokens.fromPattern(source); final List<? extends Pattern> result = parseExpr(tokens, options); if (tokens.current() != null) { throw tokens.error("unexpected ending: %s", join(" ", tokens)); } return new Required(result); }
/** * <pre> * seq ::= ( atom [ '...' ] )* ; * </pre> */ private static List<Pattern> parseSeq(final Tokens tokens, final List<Option> options) { final List<Pattern> result = list(); // >>> while tokens.current() not in [None, ']', ')', '|'] while (!in(tokens.current(), null, "]", ")", "|")) { List<? extends Pattern> atom = parseAtom(tokens, options); if ("...".equals(tokens.current())) { atom = list(new OneOrMore(atom)); tokens.move(); } result.addAll(atom); } return result; }
throws DocoptExitException { try { return doParse(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)); }
final List<? extends Pattern> u = parseExpr(tokens, options); return parseLong(tokens, options); return parseShorts(tokens, options);
private static Required parsePattern(final String source, final List<Option> options) { final Tokens tokens = Tokens.fromPattern(source); final List<? extends Pattern> result = parseExpr(tokens, options); if (tokens.current() != null) { throw tokens.error("unexpected ending: %s", join(" ", tokens)); } return new Required(result); }
/** * <pre> * seq ::= ( atom [ '...' ] )* ; * </pre> */ private static List<Pattern> parseSeq(final Tokens tokens, final List<Option> options) { final List<Pattern> result = list(); // >>> while tokens.current() not in [None, ']', ')', '|'] while (!in(tokens.current(), null, "]", ")", "|")) { List<? extends Pattern> atom = parseAtom(tokens, options); if ("...".equals(tokens.current())) { atom = list(new OneOrMore(atom)); tokens.move(); } result.addAll(atom); } return result; }
throws DocoptExitException { try { return doParse(argv);
Map<String, Object> opts = new Docopt(USAGE) .withVersion(GitRepositoryState.getRepositoryState().describe) .parse(args);
/** * Constructs an argument parser from a POSIX-style help message. * * @param doc * a POSIX-style help message * @throws DocoptLanguageError * if the help message is malformed * @see Docopt */ public Docopt(final String doc) { this.doc = doc; final List<String> usageSections = parseSection("usage:", doc); if (usageSections.size() == 0) { throw new DocoptLanguageError( "\"usage:\" (case-insensitive) not found."); } if (usageSections.size() > 1) { throw new DocoptLanguageError( "More than one \"usage:\" (case-insensitive)."); } usage = usageSections.get(0); options = parseDefaults(doc); pattern = parsePattern(formalUsage(usage), options); }
new Docopt(USAGE) .withVersion(GitRepositoryState.getRepositoryState().describe) .parse(args); String corfuConfigurationString = (String) opts.get("-c");