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
Modifier and TypeClassDescriptionstatic final class
Builder to buildSyntaxMetricsAccessor.SyntaxMetricsBuilder
instances.Nested classes/interfaces inherited from interface org.refcodes.cli.ArgumentEscapeCodeAccessor
ArgumentEscapeCodeAccessor.ArgumentEscapeCodeBuilder<B extends ArgumentEscapeCodeAccessor.ArgumentEscapeCodeBuilder<B>>, ArgumentEscapeCodeAccessor.ArgumentEscapeCodeMutator, ArgumentEscapeCodeAccessor.ArgumentEscapeCodeProperty
Nested 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.EscapeCodeStatusProperty
Nested classes/interfaces inherited from interface org.refcodes.cli.OptionEscapeCodeAccessor
OptionEscapeCodeAccessor.OptionEscapeCodeBuilder<B extends OptionEscapeCodeAccessor.OptionEscapeCodeBuilder<B>>, OptionEscapeCodeAccessor.OptionEscapeCodeMutator, OptionEscapeCodeAccessor.OptionEscapeCodeProperty
Nested 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.ResetEscapeCodeProperty
Nested classes/interfaces inherited from interface org.refcodes.cli.SyntaxMetricsAccessor
SyntaxMetricsAccessor.SyntaxMetricsBuilder<B extends SyntaxMetricsAccessor.SyntaxMetricsBuilder<B>>, SyntaxMetricsAccessor.SyntaxMetricsMutator, SyntaxMetricsAccessor.SyntaxMetricsProperty
-
Constructor Summary
ConstructorDescriptionConstructs an accordingly preconfiguredCliContext
instance.CliContext
(boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContext
instance.CliContext
(String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContext
instance.CliContext
(CliMetrics aCliMetrics) Constructs an accordingly configuredCliContext
instance.CliContext
(CliMetrics aCliMetrics, SyntaxMetrics aSyntaxMetrics) Constructs an accordingly configuredCliContext
instance.CliContext
(SyntaxMetrics aSyntaxMetrics) Constructs an accordingly configuredCliContext
instance.CliContext
(SyntaxMetrics aSyntaxMetrics, boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContext
instance.CliContext
(SyntaxMetrics aSyntaxMetrics, Character aShortOptionPrefix, String aLongOptionPrefix, boolean isEscapeCodesEnabled, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContext
instance.CliContext
(SyntaxMetrics aSyntaxMetrics, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContext
instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic CliContext.Builder
builder()
Creates aCliContext.Builder
used to fluently constructCliContext
instances.Retrieves the argument Escape-Code from the argument Escape-Code property.Retrieves the option Escape-Code from the option Escape-Code property.Retrieves theSyntaxMetrics
from theSyntaxMetrics
property.boolean
boolean
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()
).String[]
toAllOptions
(Term aConstituent) Determines all options (short and long) found in the providedTerm
node 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 theCliContext
instance specific prefixed long optionString
from the providedOption
by 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 givenOption
instance, 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 theCliContext
instance specific option notationString
(without any arguments), consisting of the short option (as oftoShortOption(Option)
) and(!)toOptionUsage
(Option<?> aOption) Creates theCliContext
instance 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 theCliContext
instance specific prefixed short optionString
from the providedOption
by prefixing theOption
's short option (as ofOption.getShortOption()
) with the short option prefix (as ofShortOptionPrefixAccessor.getShortOptionPrefix()
).Creates a notation for the givenOperand
and its arguments.Creates a specification for the givenOperand
and its arguments.
-
Constructor Details
-
CliContext
public CliContext()Constructs an accordingly preconfiguredCliContext
instance. -
CliContext
public CliContext(boolean isEscapeCodesEnabled) Constructs an accordingly configuredCliContext
instance.- Parameters:
isEscapeCodesEnabled
- Determines whether using escape codes when rendering aTerm
node's syntax.
-
CliContext
Constructs an accordingly configuredCliContext
instance.- Parameters:
aCliMetrics
- TheCliMetrics
describing theCliContext
.
-
CliContext
Constructs an accordingly configuredCliContext
instance.- Parameters:
aCliMetrics
- TheCliMetrics
describing theCliContext
.aSyntaxMetrics
- When being provided, then it overrides theSyntaxMetrics
provided by theCliMetrics
.
-
CliContext
Constructs an accordingly configuredCliContext
instance.- 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 configuredCliContext
instance.- Parameters:
aSyntaxMetrics
- TheSyntaxMetrics
describing the syntax notation to be used such as theSyntaxNotation
definitions.
-
CliContext
Constructs an accordingly configuredCliContext
instance.- Parameters:
aSyntaxMetrics
- TheSyntaxMetrics
describing the syntax notation to be used such as theSyntaxNotation
definitions.isEscapeCodesEnabled
- Determines whether using escape codes when rendering aTerm
node's syntax.
-
CliContext
public CliContext(SyntaxMetrics aSyntaxMetrics, Character aShortOptionPrefix, String aLongOptionPrefix, boolean isEscapeCodesEnabled, String aArgumentEscapeCode, String aOptionEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContext
instance.- Parameters:
aSyntaxMetrics
- TheSyntaxMetrics
describing the syntax notation to be used such as theSyntaxNotation
definitions.aShortOptionPrefix
- The short option prefix to be used when parsingOption
elements.aLongOptionPrefix
- The long option prefix to be used when parsingOption
elements.isEscapeCodesEnabled
- Determines whether using escape codes when rendering aTerm
node'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 configuredCliContext
instance.- Parameters:
aSyntaxMetrics
- TheSyntaxMetrics
describing the syntax notation to be used such as theSyntaxNotation
definitions.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:
getArgumentEscapeCode
in 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:
getOptionEscapeCode
in interfaceOptionEscapeCodeAccessor
- Returns:
- The option Escape-Code stored by the option Escape-Code property.
-
getResetEscapeCode
- Specified by:
getResetEscapeCode
in interfaceorg.refcodes.mixin.ResetEscapeCodeAccessor
-
getSyntaxMetrics
Retrieves theSyntaxMetrics
from theSyntaxMetrics
property.- Specified by:
getSyntaxMetrics
in interfaceSyntaxMetricsAccessor
- Returns:
- The
SyntaxMetrics
stored by the decorator (enabled) tags property.
-
isEscapeCodesEnabled
public boolean isEscapeCodesEnabled()- Specified by:
isEscapeCodesEnabled
in 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
Determines all options (short and long) found in the providedTerm
node and its children.- Parameters:
aConstituent
- The element (with its children if applicable) from which to determine the options.- Returns:
- An array containing all found options.
-
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
String
depending 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 theFlag
implies a argument. If theOperand
is an option, then the argument will be prefixed and suffixed different to anOperand
type.- 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 theFlag
implies an argument. If theOperand
is an option, then the argument will be prefixed and suffixed different to anOperand
type.- 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 theCliContext
instance specific prefixed long optionString
from the providedOption
by prefixing theOption
's long option (as ofOption.getLongOption()
) with the long option prefix (as ofLongOptionPrefixAccessor.getLongOptionPrefix()
). -
toOptionUsage
Creates theCliContext
instance 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 theCliContext
instance 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
String
depending 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 givenOption
instance, 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:
toOptions
in interfaceOptionable
- Parameters:
aOption
- TheOption
instance 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
String
depending on the escape code status and the reset escape code's value.
-
toShortOption
Creates theCliContext
instance specific prefixed short optionString
from the providedOption
by prefixing theOption
's short option (as ofOption.getShortOption()
) with the short option prefix (as ofShortOptionPrefixAccessor.getShortOptionPrefix()
). -
toSpec
Creates a notation for the givenOperand
and its arguments. In case of having anOption
provided, then preferably the short option is used for the specification, else the long option (as oftoOptionUsage(Option)
).- Parameters:
aOperand
- TheOperand
for which to generate the specification.- Returns:
- The according notation.
-
toUsage
Creates a specification for the givenOperand
and its arguments. In case of having anOption
provided, then the short option and the long option are declared by the notation (as oftoOptionSpec(Option)
).- Parameters:
aOperand
- TheOperand
for which to generate the specification.- Returns:
- The according specification.
-
builder
Creates aCliContext.Builder
used to fluently constructCliContext
instances.- Returns:
- The
CliContext.Builder
for constructingCliContext
instances.
-