OptionMetadata createConfigOption() { return OptionMetadata .builder(CliConfigurationSource.CONFIG_OPTION, "Specifies YAML config location, which can be a file path or a URL.") .valueRequired("yaml_location").build(); }
protected Builder() { this.option = new OptionMetadata(); this.option.valueCardinality = OptionValueCardinality.NONE; }
protected void addOption(OptionParser parser, OptionMetadata option) { // ensure non-null description String description = Optional.ofNullable(option.getDescription()).orElse(""); // TODO: how do we resolve short name conflicts? List<String> longAndShort = asList(option.getShortName(), option.getName()); OptionSpecBuilder optionBuilder = parser.acceptsAll(longAndShort, description); switch (option.getValueCardinality()) { case OPTIONAL: ArgumentAcceptingOptionSpec<String> optionSpec = optionBuilder.withOptionalArg().describedAs(option.getValueName()); if(option.getDefaultValue() != null) { optionSpec.defaultsTo(option.getDefaultValue()); } break; case REQUIRED: optionBuilder.withRequiredArg().describedAs(option.getValueName()); break; default: break; } }
if (decorator.getOptionName().equals(omd.getName())) { overrider = overrider.andThen(new InPlaceResourceOverrider(decorator.getConfigResource().getUrl(), parser, singleConfigMerger)); if (omd.getConfigPath() != null) { String cliValue = cli.optionString(omd.getName()); if (cliValue == null) { cliValue = omd.getDefaultValue(); put(omd.getConfigPath(), finalCliValue); }}, true, '.')); if (omd.getConfigResource() != null) { overrider = overrider.andThen(new InPlaceResourceOverrider(omd.getConfigResource().getUrl(), parser, singleConfigMerger));
public HelpOption(OptionMetadata option) { this.option = Objects.requireNonNull(option); this.shortNameAllowed = true; this.longNameAllowed = option.getName().length() > 1; }
public void add(OptionMetadata option) { HelpOption ho = new HelpOption(option); byShortName.computeIfAbsent(ho.getOption().getShortName(), sn -> new ArrayList<HelpOption>()).add(ho); }
private void checkNameDuplicates(Collection<OptionMetadata> options) { if (options.size() > 1) { Set<String> distinctNames = new HashSet<>(); options.forEach(om -> { if (!distinctNames.add(om.getName())) { throw new RuntimeException("Duplicate option declaration for '" + om.getName() + "'"); } }); } }
o.setShortNameAllowed(false); } else if (shortCounter[0]) { throw new IllegalStateException("Conflicting short option name: " + o.getOption().getShortName()); } else { shortCounter[0] = true;
options.forEach(o -> { String valueName = o.getOption().getValueName(); if (valueName == null || valueName.length() == 0) { valueName = "val"; if (o.isShortNameAllowed()) { parts.add("-"); parts.add(String.valueOf(o.getOption().getShortName())); switch (o.getOption().getValueCardinality()) { case REQUIRED: parts.add(" "); parts.add(o.getOption().getName()); switch (o.getOption().getValueCardinality()) { case REQUIRED: parts.add("="); String description = o.getOption().getDescription(); if (description != null) { out.printDescription(description);
/** * Returns an option representation of this command, that may be used in help generation or exposing the command * in a CLI parser. * * @return option representation of this command. * @since 0.21 */ public OptionMetadata asOption() { // TODO: cache the value? // using getters instead of vars ; some getters have logic return OptionMetadata.builder(getName()).shortName(getShortName()).description(getDescription()).build(); }
public void add(OptionMetadata option) { HelpOption ho = new HelpOption(option); byShortName.computeIfAbsent(ho.getOption().getShortName(), sn -> new ArrayList<HelpOption>()).add(ho); }
protected Builder() { this.option = new OptionMetadata(); this.option.valueCardinality = OptionValueCardinality.NONE; }
protected void addOption(OptionParser parser, OptionMetadata option) { // ensure non-null description String description = Optional.ofNullable(option.getDescription()).orElse(""); // TODO: how do we resolve short name conflicts? List<String> longAndShort = asList(option.getShortName(), option.getName()); OptionSpecBuilder optionBuilder = parser.acceptsAll(longAndShort, description); switch (option.getValueCardinality()) { case OPTIONAL: optionBuilder.withOptionalArg().describedAs(option.getValueName()); break; case REQUIRED: optionBuilder.withRequiredArg().describedAs(option.getValueName()); default: break; } }
OptionMetadata createConfigOption() { return OptionMetadata .builder(CliConfigurationSource.CONFIG_OPTION, "Specifies YAML config location, which can be a file path or a URL.") .valueRequired("yaml_location").build(); }
private OptionMetadata findMetadata(OptionSpec<?> option) { List<String> optionNames = option.options(); // TODO: allow lookup of option metadata by name to avoid linear scans... // Though we are dealing with small collection, so shouldn't be too horrible. for (OptionMetadata omd : optionMetadata) { if (optionNames.contains(omd.getName())) { return omd; } } // this was likely a command, not an option. return null; }
o.setShortNameAllowed(false); } else if (shortCounter[0]) { throw new IllegalStateException("Conflicting short option name: " + o.getOption().getShortName()); } else { shortCounter[0] = true;
options.forEach(o -> { String valueName = o.getOption().getValueName(); if (valueName == null || valueName.length() == 0) { valueName = "val"; if (o.isShortNameAllowed()) { parts.add("-"); parts.add(String.valueOf(o.getOption().getShortName())); switch (o.getOption().getValueCardinality()) { case REQUIRED: parts.add(" "); parts.add(o.getOption().getName()); switch (o.getOption().getValueCardinality()) { case REQUIRED: parts.add("="); String description = o.getOption().getDescription(); if (description != null) { out.printDescription(description);
/** * Declares a new CLI option, associating its presence with a configuration resource. This way a single option * can be used to enable a complex configuration. * * @param configResourceId a resource path compatible with {@link io.bootique.resource.ResourceFactory} denoting * a configuration source. E.g. "a/b/my.yml", or "classpath:com/foo/another.yml". * @param name the name of the new CLI option. * @return this extender instance * @since 0.24 * @deprecated since 0.25. The new way of adding an option associated with a config file is by separately declaring * an option and then associating it with one or more configs via {@link #addConfigOnOption(String, String)}. */ @Deprecated public BQCoreModuleExtender addConfigResourceOption(String configResourceId, String name) { contributeOptions().addBinding().toInstance( OptionMetadata.builder(name) .configResource(configResourceId) .valueOptional() .build()); return this; }
if (decorator.getOptionName().equals(omd.getName())) { overrider = overrider.andThen(new InPlaceResourceOverrider(decorator.getConfigResource().getUrl(), parser, singleConfigMerger)); if (pathDecorator.getOptionName().equals(omd.getName())) { String cliValue = cli.optionString(omd.getName()); overrider = overrider.andThen(new InPlaceMapOverrider( singletonMap(pathDecorator.getConfigPath(), cliValue)