The @inquirer-cli
suite provides standalone command-line interface (CLI) tools for various prompt types, leveraging the robust functionality of Inquirer.js. These tools enable developers to incorporate interactive prompts directly into shell scripts or command pipelines without the need to write custom JavaScript code.
No installation required. Simply do to start the prompt:
$ npx -y @inquirer-cli/<prompt-name> [...args]
Note: The
-y
flag is used withnpx
to skip the installation prompt. This is necessary because the CLI's output is consumed by$()
in bash, which would otherwise cause the script to freeze.
Replace <prompt-name>
with the desired prompt listed in the next section.
Each prompt type is available as a separate package under the @inquirer-cli
scope:
Each package corresponds to an Inquirer.js prompt type and is designed to be used independently.
Uses @inquirer/input.
Prompts the user for text input.
Example:
name=$(npx -y @inquirer-cli/input -r "What is your name?")
echo "Hello, $name!"
Uses @inquirer/number.
Requests a numeric input from the user.
Ask the user for their age:
age=$(npx -y @inquirer-cli/number -r "Enter your age")
echo "You are $age years old."
Uses @inquirer/confirm.
Presents a yes/no confirmation to the user.
Confirm an action with the user:
if $(npx -y @inquirer-cli/confirm "Do you want to continue?"); then
echo "Proceeding..."
else
echo "Operation cancelled."
fi
Uses @inquirer/select.
Offers a list of options for the user to select one.
Let the user choose a fruit:
fruit=$(npx "@inquirer-cli/select" -c "Apple" -c "Banana" -c "Cherry" "Pick a fruit")
echo "You selected: $fruit"
Uses @inquirer/checkbox.
Allows the user to select multiple options from a list.
Allow the user to select multiple options:
choices=$(npx -y @inquirer-cli/checkbox -r "Select your favorite colors" -c "Red" -c "Blue" -c "Green")
echo "You selected:"
for choice in $choices; do
echo "- $choice"
done
Uses @inquirer/password.
Prompts the user for sensitive information with input masking.
Prompt the user for a password:
password=$(npx -y @inquirer-cli/password -r "Enter your password")
echo "Password received. $password"
@inquirer-cli/editor
(🚧 NOT SUPPORTED YET)
@inquirer-cli/editor
I wished editor
would work like the following but sadly I couldn't make it work. Any help on this would be appreciated!
Uses @inquirer/editor.
notes=$(npx -y @inquirer-cli/editor "Write your notes")
echo "Your notes: $notes"
Each CLI prompt accepts various options to customize its behavior. Common options include:
-
--choices
(or-c
): A space-separated list of choices (applicable toselect
andcheckbox
prompts). -
--required
(or-r
): When set, empty responses will be reprompted (not applicable toconfirm
).
For a full list of options and detailed usage, refer to the documentation of the respective @inquirer-cli
package.
Licensed under the MIT License.
The @inquirer-cli
project is an independent initiative and is not affiliated with or endorsed by Inquirer.js.