Cliffy

Prompt

Cliffy’s prompt module allows you to create simple yet powerful interactive prompts for your command-line applications.

Installation

Deno

deno add jsr:@cliffy/promptCopy

Pnpm

pnpm add jsr:@cliffy/promptCopy

or (using pnpm 10.8 or older):

pnpm dlx jsr add @cliffy/promptCopy

Yarn

yarn add jsr:@cliffy/promptCopy

or (using Yarn 4.8 or older):

yarn dlx jsr add @cliffy/promptCopy

Vlt

vlt install jsr:@cliffy/promptCopy

Npm

npx jsr add @cliffy/promptCopy

Bun

bunx jsr add @cliffy/promptCopy

Usage

There are two ways of using this module. You can either use standalone (single) prompts or you can run a list of prompts that can be dynamically controlled.

Single prompt

Each prompt type is usable as standalone module and can be imported directly from the prompt specific module or from the main module. Each prompt has a static .prompt() method which accepts a prompt message or an options object and returns the prompt result.

Execute a single prompt with a message as first argument.

import { Input } from "@cliffy/prompt";

const name = await Input.prompt(`What's your name?`);Copy

Execute a single prompt with an options object as first argument.

import { Input } from "@cliffy/prompt";

const name = await Input.prompt({
  message: `Choose a username`,
  minLength: 8,
});Copy

Prompt list

To execute a list of prompts you can use the prompt() method. The prompt method accepts an array of prompt options combined with a name and type property.

i

[!NOTE] Make sure to give each prompt a unique name to prevent overwriting values!

Unlike npm’s inquirer, the type property accepts a prompt object and not the name of the prompt.

import { Checkbox, Confirm, Input, Number, prompt } from "@cliffy/prompt";

const result = await prompt([{
  name: "name",
  message: "What's your name?",
  type: Input,
}, {
  name: "age",
  message: "How old are you?",
  type: Number,
}, {
  name: "like",
  message: "Do you like animals?",
  type: Confirm,
}, {
  name: "animals",
  message: "Select some animals",
  type: Checkbox,
  options: ["dog", "cat", "snake"],
}]);

console.log(result);Copy
$ deno run examples/prompt/prompt_list.tsCopy