Class CliContext
java.lang.Object
org.refcodes.cli.CliContext
- All Implemented Interfaces:
ArgumentEscapeCodeAccessor,CliMetrics,Optionable,OptionEscapeCodeAccessor,SyntaxMetricsAccessor,org.refcodes.mixin.EscapeCodesStatusAccessor,org.refcodes.mixin.ResetEscapeCodeAccessor
The
CliContext describes the context in which an ParseArgs is
running. The CliContext may depend on the operating system or user
settings applied, when running the ParseArgs implementations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder to buildSyntaxMetricsAccessor.SyntaxMetricsBuilderinstances.Nested classes/interfaces inherited from interface org.refcodes.cli.ArgumentEscapeCodeAccessor
ArgumentEscapeCodeAccessor.ArgumentEscapeCodeBuilder<B extends ArgumentEscapeCodeAccessor.ArgumentEscapeCodeBuilder<B>>, ArgumentEscapeCodeAccessor.ArgumentEscapeCodeMutator, ArgumentEscapeCodeAccessor.ArgumentEscapeCodePropertyNested classes/interfaces inherited from interface org.refcodes.mixin.EscapeCodesStatusAccessor
org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusBuilder<B extends org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusBuilder<B>>, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusMutator, org.refcodes.mixin.EscapeCodesStatusAccessor.EscapeCodeStatusPropertyNested classes/interfaces inherited from interface org.refcodes.cli.OptionEscapeCodeAccessor
OptionEscapeCodeAccessor.OptionEscapeCodeBuilder<B extends OptionEscapeCodeAccessor.OptionEscapeCodeBuilder<B>>, OptionEscapeCodeAccessor.OptionEscapeCodeMutator, OptionEscapeCodeAccessor.OptionEscapeCodePropertyNested classes/interfaces inherited from interface org.refcodes.mixin.ResetEscapeCodeAccessor
org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeBuilder<B extends org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeBuilder<B>>, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodeMutator, org.refcodes.mixin.ResetEscapeCodeAccessor.ResetEscapeCodePropertyNested classes/interfaces inherited from interface org.refcodes.cli.SyntaxMetricsAccessor
SyntaxMetricsAccessor.SyntaxMetricsBuilder<B extends SyntaxMetricsAccessor.SyntaxMetricsBuilder<B>>, SyntaxMetricsAccessor.SyntaxMetricsMutator, SyntaxMetricsAccessor.SyntaxMetricsProperty -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an accordingly preconfiguredCliContextinstance.CliContext(boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContextinstance.CliContext(String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContextinstance.CliContext(CliMetrics aCliMetrics) Constructs an accordingly configuredCliContextinstance.CliContext(CliMetrics aCliMetrics, SyntaxMetrics aSyntaxMetrics) Constructs an accordingly configuredCliContextinstance.CliContext(CliMetrics aCliMetrics, SyntaxMetrics aSyntaxMetrics, boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContextinstance.CliContext(SyntaxMetrics aSyntaxMetrics) Constructs an accordingly configuredCliContextinstance.CliContext(SyntaxMetrics aSyntaxMetrics, boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContextinstance.CliContext(SyntaxMetrics aSyntaxMetrics, Character aShortOptionPrefix, String aLongOptionPrefix, boolean isEscapeCodesEnabled, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContextinstance.CliContext(SyntaxMetrics aSyntaxMetrics, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContextinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic CliContext.Builderbuilder()Creates aCliContext.Builderused to fluently constructCliContextinstances.Retrieves the argument Escape-Code from the argument Escape-Code property.Retrieves the option Escape-Code from the option Escape-Code property.Retrieves theSyntaxMetricsfrom theSyntaxMetricsproperty.booleanbooleanDetermines whether the given argument is an option in terms of this context, e.g. whether it starts either with a short option prefix (as ofShortOptionPrefixAccessor.getShortOptionPrefix()or a long option prefix (as ofLongOptionPrefixAccessor.getLongOptionPrefix()).String[]toAllOptions(Term aConstituent) Determines all options (short and long) found in the providedTermnode and its children.Constructs the argument escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the argument escape code is not null or null (as ofgetArgumentEscapeCode()).toArgumentSpec(Operand<?> aOperand) Creates the argument specification from the providedOperand.toArgumentSpec(Operand<?> aOperand, int aMin, int aMax) Creates the argument specification from the providedOperand.String[]toExpandOptions(String[] aArgs) Expands the provided args' short options and returns the resulting args.toLongOption(Option<?> aOption) Creates theCliContextinstance specific prefixed long optionStringfrom the providedOptionby prefixing theOption's long option (as ofOption.getLongOption()) with the long option prefix (as ofLongOptionPrefixAccessor.getLongOptionPrefix()).Constructs the option escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the option escape code is not null or null (as ofgetOptionEscapeCode()).String[]Retrieves an array of the context specific options being configured for the givenOptioninstance, being the long option (when set) and the short option (when set), by prepending the according runtime specific short option and long option prefix (if applicable).toOptionSpec(Option<?> aOption) Creates theCliContextinstance specific option notationString(without any arguments), consisting of the short option (as oftoShortOption(Option)) and(!)toOptionUsage(Option<?> aOption) Creates theCliContextinstance specific preferred prefixed optionString, being the short option (as oftoShortOption(Option)) or, in case of the short option beingnull, the long option (as oftoLongOption(Option)).Constructs the reset escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the reset escape code is not null or null (as ofgetResetEscapeCode()).toShortOption(Option<?> aOption) Creates theCliContextinstance specific prefixed short optionStringfrom the providedOptionby prefixing theOption's short option (as ofOption.getShortOption()) with the short option prefix (as ofShortOptionPrefixAccessor.getShortOptionPrefix()).Creates a specification for the givenOperandand its arguments.Creates a specification for the givenOperandand its arguments.
-
Constructor Details
-
CliContext
public CliContext()Constructs an accordingly preconfiguredCliContextinstance. -
CliContext
public CliContext(boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContextinstance.- Parameters:
isEscapeCodesEnabled- Determines whether using escape codes when rendering aTermnode's syntax.
-
CliContext
Constructs an accordingly configuredCliContextinstance.- Parameters:
aCliMetrics- TheCliMetricsdescribing theCliContext.
-
CliContext
Constructs an accordingly configuredCliContextinstance.- Parameters:
aCliMetrics- TheCliMetricsdescribing theCliContext.aSyntaxMetrics- When being provided, then it overrides theSyntaxMetricsprovided by theCliMetrics.
-
CliContext
public CliContext(CliMetrics aCliMetrics, SyntaxMetrics aSyntaxMetrics, boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContextinstance.- Parameters:
aCliMetrics- TheCliMetricsdescribing theCliContext.aSyntaxMetrics- When being provided, then it overrides theSyntaxMetricsprovided by theCliMetrics.isEscapeCodesEnabled- Overrides the accordingEscapeCodesStatusAccessor.isEscapeCodesEnabled()attribute. This is useful when using theCliContextinstance for generating exception massages which must not have ANSI escape codes.
-
CliContext
Constructs an accordingly configuredCliContextinstance.- Parameters:
aArgumentEscapeCode- The escape code to use when rendering (option's) argumentsaOptionEscapeCode- The escape code to be used when rendering options.aResetEscapeCode- The escape code resetting any previously applied escape codes.
-
CliContext
Constructs an accordingly configuredCliContextinstance.- Parameters:
aSyntaxMetrics- TheSyntaxMetricsdescribing the syntax notation to be used such as theSyntaxNotationdefinitions.
-
CliContext
Constructs an accordingly configuredCliContextinstance.- Parameters:
aSyntaxMetrics- TheSyntaxMetricsdescribing the syntax notation to be used such as theSyntaxNotationdefinitions.isEscapeCodesEnabled- Determines whether using escape codes when rendering aTermnode's syntax.
-
CliContext
public CliContext(SyntaxMetrics aSyntaxMetrics, Character aShortOptionPrefix, String aLongOptionPrefix, boolean isEscapeCodesEnabled, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContextinstance.- Parameters:
aSyntaxMetrics- TheSyntaxMetricsdescribing the syntax notation to be used such as theSyntaxNotationdefinitions.aShortOptionPrefix- The short option prefix to be used when parsingOptionelements.aLongOptionPrefix- The long option prefix to be used when parsingOptionelements.isEscapeCodesEnabled- Determines whether using escape codes when rendering aTermnode's syntax.aArgumentEscapeCode- The escape code to use when rendering (option's) argumentsaOptionEscapeCode- The escape code to be used when rendering options.aResetEscapeCode- The escape code resetting any previously applied escape codes.
-
CliContext
public CliContext(SyntaxMetrics aSyntaxMetrics, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContextinstance.- Parameters:
aSyntaxMetrics- TheSyntaxMetricsdescribing the syntax notation to be used such as theSyntaxNotationdefinitions.aArgumentEscapeCode- The escape code to use when rendering (option's) argumentsaOptionEscapeCode- The escape code to be used when rendering options.aResetEscapeCode- The escape code resetting any previously applied escape codes.
-
-
Method Details
-
getArgumentEscapeCode
Retrieves the argument Escape-Code from the argument Escape-Code property.- Specified by:
getArgumentEscapeCodein interfaceArgumentEscapeCodeAccessor- Returns:
- The argument Escape-Code stored by the argument Escape-Code property.
-
getOptionEscapeCode
Retrieves the option Escape-Code from the option Escape-Code property.- Specified by:
getOptionEscapeCodein interfaceOptionEscapeCodeAccessor- Returns:
- The option Escape-Code stored by the option Escape-Code property.
-
getResetEscapeCode
- Specified by:
getResetEscapeCodein interfaceorg.refcodes.mixin.ResetEscapeCodeAccessor
-
getSyntaxMetrics
Retrieves theSyntaxMetricsfrom theSyntaxMetricsproperty.- Specified by:
getSyntaxMetricsin interfaceSyntaxMetricsAccessor- Returns:
- The
SyntaxMetricsstored by the decorator (enabled) tags property.
-
isEscapeCodesEnabled
public boolean isEscapeCodesEnabled()- Specified by:
isEscapeCodesEnabledin interfaceorg.refcodes.mixin.EscapeCodesStatusAccessor
-
isOption
Determines whether the given argument is an option in terms of this context, e.g. whether it starts either with a short option prefix (as ofShortOptionPrefixAccessor.getShortOptionPrefix()or a long option prefix (as ofLongOptionPrefixAccessor.getLongOptionPrefix()).- Parameters:
aArg- The argument to be tested whether it matches the option pattern as of this context.- Returns:
- True in case the argument may be a short option or a long option, e.g. it is prefixed accordingly.
-
toAllOptions
-
toArgumentEscapeCode
Constructs the argument escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the argument escape code is not null or null (as ofgetArgumentEscapeCode()). In case escape codes are enabled and the argument escape code is set, then the argument escape code is returned, else an emptyString.- Returns:
- The argument escape code or an empty
Stringdepending on the escape code status and the argument escape code's value.
-
toArgumentSpec
Creates the argument specification from the providedOperand. In case we got aFlag, then there will be an empty argument specification as theFlagimplies a argument. If theOperandis an option, then the argument will be prefixed and suffixed different to anOperandtype.- Parameters:
aOperand- The operand from which to get the argument specification.- Returns:
- The argument specification.
-
toArgumentSpec
Creates the argument specification from the providedOperand. In case we got aFlag, then there will be an empty argument specification as theFlagimplies an argument. If theOperandis an option, then the argument will be prefixed and suffixed different to anOperandtype.- Parameters:
aOperand- The operand from which to get the argument specification.aMin- The minimum value for the operand.aMax- The maximum value for the operand.- Returns:
- The argument specification.
-
toExpandOptions
Expands the provided args' short options and returns the resulting args. A short option prefix may be used to denote multiple short options, given a short option prefix being used is "-", then the argument "-xyz" is expanded to be "-x", "-y" and "-z".- Parameters:
aArgs- The args to be expanded.- Returns:
- The expanded args.
-
toLongOption
Creates theCliContextinstance specific prefixed long optionStringfrom the providedOptionby prefixing theOption's long option (as ofOption.getLongOption()) with the long option prefix (as ofLongOptionPrefixAccessor.getLongOptionPrefix()). -
toOptionUsage
Creates theCliContextinstance specific preferred prefixed optionString, being the short option (as oftoShortOption(Option)) or, in case of the short option beingnull, the long option (as oftoLongOption(Option)). -
toOptionSpec
Creates theCliContextinstance specific option notationString(without any arguments), consisting of the short option (as oftoShortOption(Option)) and(!) the long option (as oftoLongOption(Option)) as of them not beingnull. -
toOptionEscapeCode
Constructs the option escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the option escape code is not null or null (as ofgetOptionEscapeCode()). In case escape codes are enabled and the option escape code is set, then the option escape code is returned, else an emptyString.- Returns:
- The option escape code or an empty
Stringdepending on the escape code status and the option escape code's value.
-
toOptions
Retrieves an array of the context specific options being configured for the givenOptioninstance, being the long option (when set) and the short option (when set), by prepending the according runtime specific short option and long option prefix (if applicable).- Specified by:
toOptionsin interfaceOptionable- Parameters:
aOption- TheOptioninstance for which to get the configured short and long options.- Returns:
- The array of options being the long option (if not null) and the short option (if not null) with the according context specific prefixes.
-
toResetEscapeCode
Constructs the reset escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the reset escape code is not null or null (as ofgetResetEscapeCode()). In case escape codes are enabled and the reset escape code is set, then the reset escape code is returned, else an emptyString.- Returns:
- The reset escape code or an empty
Stringdepending on the escape code status and the reset escape code's value.
-
toShortOption
Creates theCliContextinstance specific prefixed short optionStringfrom the providedOptionby prefixing theOption's short option (as ofOption.getShortOption()) with the short option prefix (as ofShortOptionPrefixAccessor.getShortOptionPrefix()). -
toSpec
-
toUsage
Creates a specification for the givenOperandand its arguments. In case of having anOptionprovided, then the short option and the long option are declared by the notation (as oftoOptionSpec(Option)).- Parameters:
aOperand- TheOperandfor which to generate the specification.- Returns:
- The according usage text.
-
builder
Creates aCliContext.Builderused to fluently constructCliContextinstances.- Returns:
- The
CliContext.Builderfor constructingCliContextinstances.
-