survey
Types
pub type Answer {
StringAnswer(String)
BoolAnswer(Bool)
AnswerError(AskError)
NoAnswer
}
Constructors
-
StringAnswer(String)
-
BoolAnswer(Bool)
-
AnswerError(AskError)
-
NoAnswer
pub type AskError {
Input
InvalidType
Validation
}
Constructors
-
Input
-
InvalidType
-
Validation
Configure a survey prompt to present to the user.
Question allows receiving freeform String responses
Confirmation presents the user with a [y/n] prompt to record a Bool response
pub type Survey {
Question(
prompt: String,
help: Option(String),
default: Option(String),
validate: Option(fn(String) -> Bool),
transform: Option(fn(String) -> String),
)
Confirmation(
prompt: String,
help: Option(String),
default: Option(Bool),
transform: Option(fn(Bool) -> Bool),
)
}
Constructors
-
Question( prompt: String, help: Option(String), default: Option(String), validate: Option(fn(String) -> Bool), transform: Option(fn(String) -> String), )
Question allows receiving freeform String responses
prompt
: printed prompt so the user knows expectationshelp
: optional help message to display if input is invalid or usingask_help
default
: optional default to use if empty input is received. If this is None, then input is requiredvalidate
: optional validation function to determine if input is acceptabletransform
: optional transformation function to modify input
-
Confirmation( prompt: String, help: Option(String), default: Option(Bool), transform: Option(fn(Bool) -> Bool), )
Confirmation presents the user with a [y/n] prompt to record a Bool response
prompt
: printed prompt so the user knows expectationshelp
: optional help message to display if input is invalid or usingask_help
default
: optional default to use if empty input is received. If this is None, then input is required.[y/n]
,[Y/n]
,[y/N]
are added to the prompt for default None, True, and False respectively
transform
: optional transformation function to modify input
Functions
pub fn ask_help_fn(
q: Survey,
get_line: fn(String) -> Result(String, AskError),
) -> Answer
pub fn ask_many_fn(
qs: List(#(String, Survey)),
get_lines: List(fn(String) -> Result(String, AskError)),
) -> List(#(String, Answer))
pub fn ask_many_help(
qs: List(#(String, Survey)),
) -> List(#(String, Answer))
pub fn new_confirmation(
prompt prompt: String,
help help: Option(String),
default default: Option(Bool),
transform transform: Option(fn(Bool) -> Bool),
) -> Survey
pub fn new_question(
prompt prompt: String,
help help: Option(String),
default default: Option(String),
validate validate: Option(fn(String) -> Bool),
transform transform: Option(fn(String) -> String),
) -> Survey