Class CliContext
java.lang.Object
org.refcodes.cli.CliContext
- All Implemented Interfaces:
ArgumentEscapeCodeAccessor,CliMetrics,KeywordEscapeCodeAccessor,SyntaxMetricsAccessor,org.refcodes.mixin.EscapeCodesStatusAccessor,org.refcodes.mixin.ResetEscapeCodeAccessor
The
CliContext describes the context in which an ArgsParser
is running. The CliContext may depend on the operating system or user
settings applied, when running the ArgsParser 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.KeywordEscapeCodeAccessor
KeywordEscapeCodeAccessor.KeywordEscapeCodeBuilder<B extends KeywordEscapeCodeAccessor.KeywordEscapeCodeBuilder<B>>, KeywordEscapeCodeAccessor.KeywordEscapeCodeMutator, KeywordEscapeCodeAccessor.KeywordEscapeCodePropertyNested 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 aKeywordEscapeCode, 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 aKeywordEscapeCode, String aResetEscapeCode) Constructs an accordingly configuredCliContextinstance.CliContext(SyntaxMetrics aSyntaxMetrics, String aArgumentEscapeCode, String aKeywordEscapeCode, 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 keyword (e.g. short- and long-options) 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()).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()).String[]toExpandOptions(String[] aArgs) Expands the provided args' short options and returns the resulting args.Constructs the keyword escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the keyword escape code is not null (as ofgetKeywordEscapeCode()).String[]toKeywords(Term aTerm) Determines all keywords (e.g. short- and long-options) found in the providedTermnode and its children.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()).
-
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) argumentsaKeywordEscapeCode- The escape code to be used when rendering keywords (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 aKeywordEscapeCode, 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) argumentsaKeywordEscapeCode- 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 aKeywordEscapeCode, 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) argumentsaKeywordEscapeCode- 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.
-
getKeywordEscapeCode
Retrieves the keyword (e.g. short- and long-options) Escape-Code from the option Escape-Code property.- Specified by:
getKeywordEscapeCodein interfaceKeywordEscapeCodeAccessor- Returns:
- The keyword (e.g. short- and long-options) 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.
-
toKeywords
-
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.
-
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.
-
toKeywordEscapeCode
Constructs the keyword escape code depending on the escape code status (as ofisEscapeCodesEnabled()) and whether the keyword escape code is not null (as ofgetKeywordEscapeCode()). In case escape codes are enabled and the keyword escape code is set, then the keyword escape code is returned, else an emptyString.- Returns:
- The keyword escape code or an empty
Stringdepending on the escape code status and the keyword escape code's value.
-
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.
-
builder
Creates aCliContext.Builderused to fluently constructCliContextinstances.- Returns:
- The
CliContext.Builderfor constructingCliContextinstances.
-