Go Conference 2019 Spring https://gocon.jp/2019-spring-sessions#h7-s-we-want-awesome-cli-tool--development
We want AWESOME CLItool & developmentGo Conference 2019 Spring@micnncim
View Slide
$ whoami@micnncim @micnncimUniversity Student (CS/B4)No Job (Welcome job opportunity!)Blog: https://micnncim.github.io/
CLI, UNIX, Go
A Quarter-Century of Unix (1994)Write programs that do one thing and do it well.Write programs to work together.Write programs to handle text streams,because that is a universal interface.
Why Go for CLI?ばば
What component?ば Argument/Flag/(Subcommand)ば I/O (Standard Stream)ば Exit Code
What needed for awesome CLI?ば UX/DXばばばば
Design and Test CLI
Design & Test I/Oば fmt.Println()Testableば io.Writerば I/O interface
Design I/O
Test I/O
Design I/OFrom github/hub
Design I/OFrom mitchellh/cli
Test I/Oば bytes.Bu er
Handling Exit Codeば error Exit Code 0ば Exit Codeば Exit Code error type
Handling Exit CodeFrom github/hub
Test with golden filesば ( ).goldenばAPI .golden
Test with golden files
Test with golden filesば testdata/expect.golden
Cross Platform
Support Cross Platformば Go Linux/macOS/Windowsば Utility
Pkgs for Cross Platformば Home Directory: mitchellh/go-homedirば Open ( | URL): skratchdot/open-golangば Color: mattn/go-colorable
Pkgs for Cross PlatformFrommitchellh/go-homedir
Build & Release CLI
Build & Releaseば $ go get potentially unstable, Goば GitHub Release curl + tar + chmod?ば
Build & Releaseば mitchellh/gox:ば tcnksm/ghr:ば goreleaser/goreleaser:, , etc.
GoReleaserば YAMLば Homebrewば CI easy
GoReleaser: Buildば YAMLばDX
GoReleaser: Changelogば Changelog= UX
GoReleaser: Package Managerば FormulaばDXば UX
CI/CDば tag push CI
CI/CDば GoReleaser dead simpleGoReleaser dead simple
Updateばば CLI GUIば rhysd/go-github-selfupdate tj/go-update
Auto Update
Document CLI
Documentationば Go( | )ばば ( )
Demoば GIF? SVG?ば troublesomeば asciinema + (asciicast2gif | svg-term-cli)
Demo
Develop Rich CLI
Awesome CLI packagesば All in Oneば Flag Parserば Standard Streamば Progress UIば Con guration
All in Oneば urfave/cli 10,714ば spf13/cobra 11,958ば mitchellh/cli 966, ,, etc.
All in One
Flag Parserば alecthomas/kingpin 2,431ば jessevdk/go- ags 1,458,, ag/argument,ag parse
Flag Parser
Standard Streamば manifoldco/promptui 2,803ば AlecAivazis/survey 1,144validation,Select, Con rm, Password UIUX Stdin UIUtility
Standard Stream
Progress UIば cheggaaa/pb 1,878ば gosuri/uiprogress 1,400ば briandowns/spinner 734I/O ,Spinner UI
Progress UI
Configurationば spf13/viper 8,467JSON/TOML/YAML/HCLCon g ,, Path
Example
micnncim/bitbrew✔ Document, Demo
micnncim/bitbrew✔
micnncim/bitbrew✔ Testable I/O
micnncim/bitbrew✔ Con g
micnncim/bitbrew✔ Rich UI
micnncim/bitbrew✔ Installation
See alsoば golang/goば hashicorp/consul, terraform, nomad, packer, etc.
@micnncimThank you!