Chapter 01無料公開

Stripe CLIとは / インストール方法

hidetaka okamoto
hidetaka okamoto
2022.01.05に更新

Stripe CLIはStripe社が提供しているCLIツールです。

Stripeに登録された顧客データや商品情報の取得・操作、Stripe Webhookのデバッグ、Stripeのイベントログ取得、APIモックオブジェクトの作成など、主に開発や運用保守に活用できます。

Stripe CLIをインストールする

Stripe CLIはmacOS / Linux / Windowsなど、さまざまなプラットフォームで実行できます。

Homebrewを使ったインストール

Homebrewを使ってのインストールが簡単です。

$ brew install stripe/stripe-cli/stripe

macOS / Windowsでのインストール

macOSやWindowsの場合、GitHubのReleaseからダウンロードします。

https://github.com/stripe/stripe-cli/releases/latest

macOSの場合は「stripe_X.X.X_mac-os_x86_64.tar.gz」Windowsの場合は「stripe_X.X.X_windows_x86_64.zip」のように、各OS毎にDLファイルが用意されています。

これをDLし、実行することでStripe CLIを利用できるようになります。

その他の環境でのインストール方法は、Stripeドキュメントを確認してください。
https://stripe.com/docs/stripe-cli#install

[macOS / Linux向け] stripe completionでCLI入力補完を設定する

※本書執筆時点のバージョン(1.7.9)ではWindowsは未対応です。

bashやzshを使っている場合、stripe completionで入力補完を設定できます。

% stripe completion
Detected `zsh`, generating zsh completion file: stripe-completion.zsh

Suggested next steps:
---------------------
1. Move `stripe-completion.zsh` to the correct location:
    mkdir -p ~/.stripe
    mv stripe-completion.zsh ~/.stripe

2. Add the following lines to your `.zshrc` enabling shell completion for Stripe:
    fpath=(~/.stripe $fpath)
    autoload -Uz compinit && compinit -i

3. Source your `.zshrc` or open a new terminal session:
    source ~/.zshrc

stripe completionを実行すると、bashまたはzshに応じたstripe-completionファイルが生成されます。

これをコマンドが指示する通り、移動させて、RCファイルに設定を追加すればOKです。

% mkdir -p ~/.stripe
% mv stripe-completion.zsh ~/.stripe
% vim ~/.zshrc
# The next lines enables shell command completion for Stripe
fpath=(~/.stripe $fpath)
autoload -Uz compinit && compinit -i

 % source ~/.zshrc

これで、[Tabキー]を使ったコマンドの入力補完が利用できるようになりました。

% stripe customer
customer_balance_transactions  customers  --    

Column: Stripe CLIプロジェクトへの参加

Stripe CLIはApache-2.0 LicenseでライセンスされたOSSです。

GitHub上でIssueやPull Requestのやりとりも活発ですので、もしCLIの仕様や挙動で気になることを調べたり、バグの報告などを行いたい場合は、 https://github.com/stripe/stripe-cli からIssueを作成しましょう。

開発チームが英語を主言語としているため、IssueやPull Requestは英語で書く必要があります。が、Google翻訳( https://translate.google.com/ )や DeepL翻訳( https://www.deepl.com/translator )などで英訳しながら文章を作れば、よほど複雑な議論でない限り意図は伝わるはずです。