inquire

An OCaml library to create beautiful interactive CLIs
README

An OCaml library to create beautiful interactive CLIs.

Installation

Using Opam

opam install inquire

Using Esy

esy add @opam/inquire

Usage

Confirm

Prompt the user to answer the given message with "y" or "n".

Inquire.confirm "Are you sure?"

Raw List

Prompt the user to chose a value from the given options.

Inquire.raw_select "What's your favorite movie?" ~options:[ "Choice 1" ; "Choice 2" ]

Password

Prompt the user to enter a password that will be hidden with stars (*).

Inquire.password "Enter your password:"

Input

Prompt the user to input a string.

Inquire.input "Enter a value:"

Custom Implementation

Create a custom implementation to style Inquire's prompts.

module CustomInquire = Inquire.Make (struct
  open LTerm_style
  open LTerm_text

  let make_prompt message =
    eval
      [ B_fg green; S "? "; B_fg white; S (Printf.sprintf "%s" message); E_fg ]

  let make_error message =
    eval
      [ B_fg green; S "X "; B_fg white; S (Printf.sprintf "%s" message); E_fg ]

  let make_select ~current options =
    List.mapi options ~f:(fun index option ->
        if current = index then
          [ B_fg green
          ; S "> "
          ; B_fg white
          ; S (Printf.sprintf "%s\n" option)
          ; E_fg
          ]
        else
          [ S "  "; B_fg white; S (Printf.sprintf "%s\n" option); E_fg ])
    |> List.concat
    |> eval
end)

let _ =
  let result = CustomInquire.confirm "Are you sure?" ~default:true in
  Lwt_main.run result

Contributing

Developing

You need Opam, you can install it by following Opam's documentation.

With Opam installed, you can install the dependencies with:

opam install --deps-only --with-test -y .

Then, build the project with:

make

Running Examples

After building the project, you can run the example binaries with:

dune exec examples/<example>.exe

For instance, to run the confirm.ml example, you can type:

dune exec examples/confirm.exe

Running Tests

You can test compiled executable with:

make test

Building documentation

Documentation for the libraries in the project can be generated with:

make doc
open-cli $(make doc-path)

This assumes you have a command like open-cli installed on your system.

Create new releases

To create a release and publish it on Opam, you can run the script script/release.sh. It will create a tag with the version found in inquire.opam, and push it on your repository.

From there, the CI/CD will take care of publishing your documentation, create a github release, and open a PR with your version on opam-repository.

Repository Structure

The following snippet describes Inquire's repository structure.

.
├── examples/
|   Source for inquire's examples. This links to the library defined in `lib/`.
│
├── lib/
|   Source for Inquire's library. Contains Inquire's core functionnalities.
│
├── test/
|   Unit tests and integration tests for Inquire.
│
├── dune-project
|   Dune file used to mark the root of the project and define project-wide parameters.
|   For the documentation of the syntax, see https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
│
├── LICENSE
│
├── README.md
│
└── inquire.opam
    Opam package definition.
    To know more about creating and publishing opam packages, see https://opam.ocaml.org/doc/Packaging.html.
Install
Published
11 May 2020
Maintainers
Sources
inquire-0.2.0.tbz
sha256=730d6baf42067aa567040b5e60bc9d5a0ace4a7a819708630adf142d101d9032
sha512=dbc281aa40c9b676b0833ee35fc485b44fabf1daed9f5bd02413982919a1d2cc7f19863cec891a244cb193036ecf3284972b50e4d4d1419e90d8fa58acfcde12
Dependencies
zed
>= "2.0"
lambda-term
< "3.3.0"
dune
>= "2.0"
ocaml
>= "4.08.0"
Reverse Dependencies
spin
= "0.6.0"