public ParsedCommand invoke()

in meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java [293:335]


        public ParsedCommand invoke() {
            final org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();
            options.addOption(null, "help", false, "Show help");
            options.addOption(null, "context", true, "The context to use to deploy the webapp");
            options.addOption(null, "webapp", true, "Location of the webapp, if not set the classpath will be deployed");
            options.addOption(null, "docbase", true, "Location of the docbase for a classpath deployment");
            final List<Field> fields = Stream.of(Configuration.class.getDeclaredFields())
                    .filter(f -> f.isAnnotationPresent(CliOption.class))
                    .collect(toList());
            final Map<Object, List<Field>> propertiesOptions = StreamSupport.stream(ServiceLoader.load(Options.class).spliterator(), false)
                    .collect(toMap(identity(), o -> Stream.of(o.getClass().getDeclaredFields()).filter(f -> f.isAnnotationPresent(CliOption.class)).collect(toList())));
            fields.forEach(f -> {
                final CliOption opt = f.getAnnotation(CliOption.class);
                final String description = opt.description();
                options.addOption(null, opt.name(), true /*even for booleans otherwise no way to set false for true by default ones*/, description);
                Stream.of(opt.alias()).forEach(a -> options.addOption(null, a, true, description));
            });
            propertiesOptions.values().forEach(all -> all.forEach(f -> {
                final CliOption opt = f.getAnnotation(CliOption.class);
                final String description = opt.description();
                options.addOption(null, opt.name(), true, description);
                Stream.of(opt.alias()).forEach(a -> options.addOption(null, a, true, description));
            }));

            final CommandLineParser parser = new DefaultParser();
            try {
                line = parser.parse(options, args, true);
            } catch (final ParseException exp) {
                help(options);
                failed = true;
                return this;
            }

            if (line.hasOption("help")) {
                help(options);
                failed = true;
                return this;
            }

            builder = buildConfig(line, fields, propertiesOptions);
            failed = false;
            return this;
        }