diff options
author | Googler <noreply@google.com> | 2017-06-27 20:05:20 +0200 |
---|---|---|
committer | Marcel Hlopko <hlopko@google.com> | 2017-06-28 10:18:05 +0200 |
commit | 7c7255ec8d6da20526c2c4078c57aadaf3dd3612 (patch) | |
tree | 4da3cb1a572edcdf7f883cb1edc56d733f6302bc /src/main/java/com/google/devtools/common/options/OptionsParser.java | |
parent | 1b2e451e7fba2616b850f531f76f577a3c59fda9 (diff) |
Allow expansion flags to have values.
This lets us change what it expands based on the argument passed to the flag.
RELNOTES: Allows flags that expand to take values.
PiperOrigin-RevId: 160298412
Diffstat (limited to 'src/main/java/com/google/devtools/common/options/OptionsParser.java')
-rw-r--r-- | src/main/java/com/google/devtools/common/options/OptionsParser.java | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/common/options/OptionsParser.java b/src/main/java/com/google/devtools/common/options/OptionsParser.java index 728c49070e..c007db87a1 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsParser.java +++ b/src/main/java/com/google/devtools/common/options/OptionsParser.java @@ -239,7 +239,7 @@ public class OptionsParser implements OptionsProvider { private final Converter<?> converter; private final boolean allowMultiple; - private final ImmutableList<OptionValueDescription> expansions; + private final OptionsData.ExpansionData expansionData; private final ImmutableList<OptionValueDescription> implicitRequirements; OptionDescription( @@ -247,13 +247,13 @@ public class OptionsParser implements OptionsProvider { Object defaultValue, Converter<?> converter, boolean allowMultiple, - ImmutableList<OptionValueDescription> expansions, + OptionsData.ExpansionData expansionData, ImmutableList<OptionValueDescription> implicitRequirements) { this.name = name; this.defaultValue = defaultValue; this.converter = converter; this.allowMultiple = allowMultiple; - this.expansions = expansions; + this.expansionData = expansionData; this.implicitRequirements = implicitRequirements; } @@ -277,8 +277,14 @@ public class OptionsParser implements OptionsProvider { return implicitRequirements; } - public ImmutableList<OptionValueDescription> getExpansions() { - return expansions; + public boolean isExpansion() { + return !expansionData.isEmpty(); + } + + /** Return a list of flags that this option expands to. */ + public ImmutableList<String> getExpansion(ExpansionContext context) + throws OptionsParsingException { + return expansionData.getExpansion(context); } } @@ -658,21 +664,33 @@ public class OptionsParser implements OptionsProvider { * @return The {@link OptionDescription} for the option, or null if there is no option by the * given name. */ - public OptionDescription getOptionDescription(String name) throws OptionsParsingException { + OptionDescription getOptionDescription(String name) throws OptionsParsingException { return impl.getOptionDescription(name); } /** - * Returns a description of the option value set by the last previous call to - * {@link #parse(OptionPriority, String, List)} that successfully set the given - * option. If the option is of type {@link List}, the description will - * correspond to any one of the calls, but not necessarily the last. + * Returns a description of the options values that get expanded from this flag with the given + * flag value. + * + * @return The {@link ImmutableList<OptionValueDescription>} for the option, or null if there is + * no option by the given name. + */ + ImmutableList<OptionValueDescription> getExpansionOptionValueDescriptions( + String flagName, @Nullable String flagValue) throws OptionsParsingException { + return impl.getExpansionOptionValueDescriptions(flagName, flagValue); + } + + /** + * Returns a description of the option value set by the last previous call to {@link + * #parse(OptionPriority, String, List)} that successfully set the given option. If the option is + * of type {@link List}, the description will correspond to any one of the calls, but not + * necessarily the last. * * @return The {@link OptionValueDescription} for the option, or null if the value has not been - * set. + * set. * @throws IllegalArgumentException if there is no option by the given name. */ - public OptionValueDescription getOptionValueDescription(String name) { + OptionValueDescription getOptionValueDescription(String name) { return impl.getOptionValueDescription(name); } |