Slide 1

Slide 1 text

We want AWESOME CLI tool & development Go Conference 2019 Spring @micnncim

Slide 2

Slide 2 text

$ whoami @micnncim @micnncim University Student (CS/B4) No Job (Welcome job opportunity!) Blog: https://micnncim.github.io/

Slide 3

Slide 3 text

CLI, UNIX, Go

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

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.

Slide 6

Slide 6 text

Why Go for CLI? ば ば

Slide 7

Slide 7 text

What component? ば Argument/Flag/(Subcommand) ば I/O (Standard Stream) ば Exit Code

Slide 8

Slide 8 text

What needed for awesome CLI? ば UX/DX ば ば ば ば

Slide 9

Slide 9 text

Design and Test CLI

Slide 10

Slide 10 text

Design & Test I/O ば fmt.Println() Testable ば io.Writer ば I/O interface

Slide 11

Slide 11 text

Design I/O

Slide 12

Slide 12 text

Test I/O

Slide 13

Slide 13 text

Design I/O

Slide 14

Slide 14 text

Design I/O From github/hub

Slide 15

Slide 15 text

Design I/O From mitchellh/cli

Slide 16

Slide 16 text

Test I/O ば bytes.Bu er

Slide 17

Slide 17 text

Handling Exit Code ば error Exit Code 0 ば Exit Code ば Exit Code error type

Slide 18

Slide 18 text

Handling Exit Code From github/hub

Slide 19

Slide 19 text

Test with golden files ば ( ) .golden ば API .golden

Slide 20

Slide 20 text

Test with golden files

Slide 21

Slide 21 text

Test with golden files ば testdata/expect.golden

Slide 22

Slide 22 text

Test with golden files

Slide 23

Slide 23 text

Cross Platform

Slide 24

Slide 24 text

Support Cross Platform ば Go Linux/macOS/Windows ば Utility

Slide 25

Slide 25 text

Pkgs for Cross Platform ば Home Directory: mitchellh/go-homedir ば Open ( | URL): skratchdot/open-golang ば Color: mattn/go-colorable

Slide 26

Slide 26 text

Pkgs for Cross Platform From mitchellh/go-homedir

Slide 27

Slide 27 text

Build & Release CLI

Slide 28

Slide 28 text

Build & Release ば $ go get potentially unstable, Go ば GitHub Release curl + tar + chmod? ば

Slide 29

Slide 29 text

Build & Release ば mitchellh/gox: ば tcnksm/ghr: ば goreleaser/goreleaser: , , etc.

Slide 30

Slide 30 text

GoReleaser ば YAML ば Homebrew ば CI easy

Slide 31

Slide 31 text

GoReleaser: Build ば YAML ば DX

Slide 32

Slide 32 text

GoReleaser: Changelog ば Changelog = UX

Slide 33

Slide 33 text

GoReleaser: Package Manager ば Formula ば DX ば UX

Slide 34

Slide 34 text

CI/CD ば tag push CI

Slide 35

Slide 35 text

CI/CD ば GoReleaser dead simple GoReleaser dead simple

Slide 36

Slide 36 text

Update ば ば CLI GUI ば rhysd/go-github-selfupdate tj/go-update

Slide 37

Slide 37 text

Auto Update

Slide 38

Slide 38 text

Document CLI

Slide 39

Slide 39 text

Documentation ば Go ( | ) ば ば ( )

Slide 40

Slide 40 text

Demo ば GIF? SVG? ば troublesome ば asciinema + (asciicast2gif | svg-term-cli)

Slide 41

Slide 41 text

Demo

Slide 42

Slide 42 text

Develop Rich CLI

Slide 43

Slide 43 text

Awesome CLI packages ば All in One ば Flag Parser ば Standard Stream ば Progress UI ば Con guration

Slide 44

Slide 44 text

All in One ば urfave/cli 10,714 ば spf13/cobra 11,958 ば mitchellh/cli 966 , , , etc.

Slide 45

Slide 45 text

All in One

Slide 46

Slide 46 text

Flag Parser ば alecthomas/kingpin 2,431 ば jessevdk/go- ags 1,458 , , ag/argument, ag parse

Slide 47

Slide 47 text

Flag Parser

Slide 48

Slide 48 text

Standard Stream ば manifoldco/promptui 2,803 ば AlecAivazis/survey 1,144 validation, Select, Con rm, Password UI UX Stdin UI Utility

Slide 49

Slide 49 text

Standard Stream

Slide 50

Slide 50 text

Progress UI ば cheggaaa/pb 1,878 ば gosuri/uiprogress 1,400 ば briandowns/spinner 734 I/O , Spinner UI

Slide 51

Slide 51 text

Progress UI

Slide 52

Slide 52 text

Configuration ば spf13/viper 8,467 JSON/TOML/YAML/HCL Con g , , Path

Slide 53

Slide 53 text

Example

Slide 54

Slide 54 text

micnncim/bitbrew ✔ Document, Demo

Slide 55

Slide 55 text

micnncim/bitbrew ✔

Slide 56

Slide 56 text

micnncim/bitbrew ✔

Slide 57

Slide 57 text

micnncim/bitbrew ✔ Testable I/O

Slide 58

Slide 58 text

micnncim/bitbrew ✔ Con g

Slide 59

Slide 59 text

micnncim/bitbrew ✔ Rich UI

Slide 60

Slide 60 text

micnncim/bitbrew ✔ Installation

Slide 61

Slide 61 text

See also ば golang/go ば hashicorp/consul, terraform, nomad, packer, etc.

Slide 62

Slide 62 text

@micnncim Thank you!