LoginSignup
0
0

More than 1 year has passed since last update.

デプロイコマンドを実行する際に対話形式で確認

Last updated at Posted at 2020-09-09

デプロイのコマンドを実行する際に、処理継続の確認をするためのスクリプトを書きます。
指定された入力があれば、そのあとの処理を続けて実行、指定と違えばそこで終了します。

作成

confirm.sh
#!/bin/bash

LAST_STAND=$1

function Confirm() {
    QUESTION=$1
    ANSWER=$2
    NOTE=$3
    ANOTATION=$4
    read -p $'\033[0;34m?\033[0;39m'" ${QUESTION}: "$'\033[1;30m('"${NOTE}"$')\033[0;39m ' INPUT

    if [ -z "${INPUT}" ] || [ "${INPUT}" != "${ANSWER}" ]; then
        echo "\n\033[0;31m${ANOTATION:-スクリプトを終了します。}\033[0;39m"
        exit 1
    fi
}

Confirm "処理を続行する場合は「${LAST_STAND}」と入力してください。" "${LAST_STAND}" "${LAST_STAND}"

echo "\n\033[0;32mスクリプトを実行します。\033[0;39m"

設定

package.json
{
  "scripts": {
    "predeploy": "sh confirm.sh DEPLOY"
    "deploy": "echo deploy"
  }
}

実行

$ npm run deploy
0
0
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
0
0