LoginSignup
7
7

More than 5 years have passed since last update.

Inquirer.jsを使用してコマンドライン上で対話形式での質問を行う

Posted at

Inquire.jsを使用すると、コマンドライン上での入力指示がとても捗る。

入力としては、通常のテキスト入力、リストからの選択、チェックボックス、yes/no、パスワード入力などから選ぶことができる。

とりあえず、リストからの入力とテキスト入力を試してみたよ - GIFアニメ

https://gyazo.com/225a1acbf194bbccc2fee4965217bf62

ソース

index.js
"use strict";
let inquirer = require("inquirer");
let myQuestion = {
    "type": "list",
    "name": "myQuestion1",
    "message": "choice mood",
    "choices": ["good", "sad"]
};
let myQuestion2 = {
    "type": "input",
    "name": "myQuestion2",
    "message": "もうう少し詳しく教えて下さい。"
};
inquirer.prompt([myQuestion, myQuestion2], (answer) => {
    console.log("answer:" + answer.myQuestion1, answer.myQuestion2);
});

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7