Skip to content

araera111/inquirer_oc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inquirer_oc

What does "inquirer_oc" library do?

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.

  1. list
  2. input
  3. confirm

usage

list

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

image result

advanced

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

input

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

image result

confirm

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)

image result

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages