Class BaseAsker
- All Implemented Interfaces:
Asker
- Direct Known Subclasses:
AskAsAsker
,AttributeAsker
,CompatAsker
,CompositeAsker
,ExpressionAsker
Base implementation of an Asker that cuts down on boiler plate and also binds the user's input (for validation purposes) before returning the unbound value back to the survey (to make sure that it will bind and the UI isn't doing some magic it's not allowed to - keep in mind that while this UI is part of the same process as the riskscape engine, the wizard has been built so that it can work with a future web UI without huge amounts of re-work)
-
Field Summary
Modifier and TypeFieldDescriptionprotected final nz.org.riskscape.engine.i18n.EnumTranslator
protected final nz.org.riskscape.engine.i18n.TranslationContext
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.wizard.Answer.Response>
ask
(AskRequest input) Get a bound value from the user - note that the response's original input is returned fromaskUnbound(AskRequest)
.nz.org.riskscape.problem.ResultOrProblems<Object>
askUnbound
(AskRequest input) Drive the givenCliPrompter
to answer the givenQuestion
.getChoices
(Class<T> enumClass) protected Locale
protected String
getMessage
(String suffix, Object... args) protected nz.org.riskscape.engine.i18n.MessageSource
getOptionalMessage
(String suffix, Object... args) Search for a message for this class, conventionally by prepending the class's name to the code, searching through the class hierarchy as well as looking for short class names as well as long names.nz.org.riskscape.wizard.Choice
pickChoice
(List<nz.org.riskscape.wizard.Choice> choices, CliPrompter prompter, nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text prompt) toChoice
(nz.org.riskscape.engine.i18n.EnumTranslator.EnumEntry<T> entry) Allows individual Askers to potentially override how enums get displayed to the user
-
Field Details
-
translationContext
protected final nz.org.riskscape.engine.i18n.TranslationContext translationContext -
enumTranslator
protected final nz.org.riskscape.engine.i18n.EnumTranslator enumTranslator
-
-
Constructor Details
-
BaseAsker
public BaseAsker(nz.org.riskscape.engine.i18n.TranslationContext context)
-
-
Method Details
-
getChoices
- Returns:
- a list of (translated)
CliChoice
s for a given enum, that the user can pick between
-
toChoice
protected <T extends Enum<?>> CliChoice<T> toChoice(nz.org.riskscape.engine.i18n.EnumTranslator.EnumEntry<T> entry) Allows individual Askers to potentially override how enums get displayed to the user
-
getMessage
-
getOptionalMessage
Search for a message for this class, conventionally by prepending the class's name to the code, searching through the class hierarchy as well as looking for short class names as well as long names.
Searches through wizard resources only (for now - we may fall back to help text for enums for example?)
For example, a class com.Foo than extends org.Bar would search for messages under 'com.Foo', 'Foo', 'org.Bar', and then 'Bar'.
- Parameters:
suffix
- a message key to append to the class derived part of the codeargs
- args to interpolate in to the message- Returns:
- a message, or empty if none could be found
-
ask
public abstract nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.wizard.Answer.Response> ask(AskRequest input) Get a bound value from the user - note that the response's original input is returned from
askUnbound(AskRequest)
. This is partly here because the original API exposed this method on the interface, and keeping this method here keeps the refactoring/change noise down to a minimum while allowing the interface to change in the way we want to preserve the right amount of encapsulation -
askUnbound
Description copied from interface:Asker
Drive the given
CliPrompter
to answer the givenQuestion
. Assume thatAsker.canAsk(IncrementalBuildState, Question)
has already been tested and returned true.- Specified by:
askUnbound
in interfaceAsker
- Returns:
- an unbound object that should be able to be bound to a value of the type in the input's question, or problems if it failed
-
getLocale
-
getMessageSource
protected nz.org.riskscape.engine.i18n.MessageSource getMessageSource() -
pickChoice
public nz.org.riskscape.wizard.Choice pickChoice(List<nz.org.riskscape.wizard.Choice> choices, CliPrompter prompter, nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text prompt)
-