CLIの設計

Topic

golangCLIを(しっかり設計して)作ってみる。設計で意識するところ

Summary

Sentence Readability

Antipattern

  • Avoid positional arguments where the order matters

emote add repo funk https://x.com/funk.json 🤔

emote add repo https://x.com/funk.json funk 😓

emote add repo funk --url https://x.com/funk.json

3つ目が好みだと言っている。

第1引数~3引数はpositional → lnとかの順序に合わせる → ここまではユーザーが推測しやすい

ln -s <File name> <Link name> を連想する可能性が高いので認識コストが低いはず

4つ目はパラメーターにしちゃう。こうすると順序問題は関係なくなる

自動化のサポート

  • —outputコマンドでjsonなりmachine readableな形式でも出力できるようにしてあげる

Implicit Resources in the Domain

$emote list

helpのカスタマイズ

よくある全てのオプションやフラグについてのhelpよりも、ユーザーが何をすべきかのガイダンスを表示するほうがいい

f:id:mizushou:20201214083805p:plain

Piping is good for automation but people don't want to pipe

golang cobra 使い方ググるCLIの記事が結構出てくる

次回は21:43あたりのLet's build a CLI!から

How's day been?

Good 😉