Allow interaction on the CLI For example, you can have the user select one from multiple lists.
Currently, three types of question formats are implemented.
- list
- input
- confirm
open Inquirer_oc
let question_option : Question_list_type.question =
{
name = "flower";
prompt_type = List;
message = "What's your favorite flower?";
choices =
[
{ word = "Sunflower"; value = "sunflower" };
{ word = "Tulip"; value = "tulip" };
{ word = "Rose"; value = "rose" };
{ word = "Daisy"; value = "daisy" };
{ word = "Lily"; value = "lily" };
];
page_size = Some 5;
}
let result = Question_list.list_question question_option
let () = print_endline result
If you want a simple string list with word and value together, there is a function to convert.
open Inquirer_oc
(* string list *)
let flower_list = [ "sunflower"; "tulip"; "rose"; "daisy"; "lily" ]
let question_option : Question_list_type.question =
{
name = "flower";
prompt_type = List;
message = "What's your favorite flower?";
(* convert choices string x -> {word: x; value: x} *)
choices = Question_list.string_list_to_choice_list flower_list;
page_size = Some 5;
}
let result = Question_list.list_question question_option
let () = print_endline result
open Inquirer_oc
let question_option : Question_input_type.question_input_option =
{
name = "flower";
prompt_type = Input;
message = "What's your favorite flower?";
default = Some "rose";
}
let result = Question_input.question_input question_option
let () = print_endline result
open Inquirer_oc
let question_option : Question_confirm_type.question_confirm_option =
{
name = "confirm";
message = "Are you sure?";
prompt_type = Confirm;
default = Some true;
}
let result = Question_confirm.inquirer_confirm question_option
let () = print_string (string_of_bool result)