Upgrade to Pro — share decks privately, control downloads, hide ads and more …

We want AWESOME CLI tool & development

We want AWESOME CLI tool & development

micnncim

May 18, 2019
Tweet

More Decks by micnncim

Other Decks in Programming

Transcript

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

    View full-size slide

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

    View full-size slide

  3. CLI, UNIX, Go

    View full-size slide

  4. 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.

    View full-size slide

  5. Why Go for CLI?


    View full-size slide

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

    View full-size slide

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




    View full-size slide

  8. Design and Test CLI

    View full-size slide

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

    View full-size slide

  10. Design I/O
    From github/hub

    View full-size slide

  11. Design I/O
    From mitchellh/cli

    View full-size slide

  12. Test I/O
    ば bytes.Bu er

    View full-size slide

  13. Handling Exit Code
    ば error Exit Code 0
    ば Exit Code
    ば Exit Code error type

    View full-size slide

  14. Handling Exit Code
    From github/hub

    View full-size slide

  15. Test with golden files
    ば ( )
    .golden

    API .golden

    View full-size slide

  16. Test with golden files

    View full-size slide

  17. Test with golden files
    ば testdata/expect.golden

    View full-size slide

  18. Test with golden files

    View full-size slide

  19. Cross Platform

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. Pkgs for Cross Platform
    From
    mitchellh/go-homedir

    View full-size slide

  23. Build & Release CLI

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  26. GoReleaser
    ば YAML
    ば Homebrew
    ば CI easy

    View full-size slide

  27. GoReleaser: Build
    ば YAML

    DX

    View full-size slide

  28. GoReleaser: Changelog
    ば Changelog
    = UX

    View full-size slide

  29. GoReleaser: Package Manager
    ば Formula

    DX
    ば UX

    View full-size slide

  30. CI/CD
    ば tag push CI

    View full-size slide

  31. CI/CD
    ば GoReleaser dead simple
    GoReleaser dead simple

    View full-size slide

  32. Update

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

    View full-size slide

  33. Document CLI

    View full-size slide

  34. Documentation
    ば Go
    ( | )

    ば ( )

    View full-size slide

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

    View full-size slide

  36. Develop Rich CLI

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  41. Standard Stream

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  44. micnncim/bitbrew
    ✔ Document, Demo

    View full-size slide

  45. micnncim/bitbrew

    View full-size slide

  46. micnncim/bitbrew

    View full-size slide

  47. micnncim/bitbrew
    ✔ Testable I/O

    View full-size slide

  48. micnncim/bitbrew
    ✔ Con g

    View full-size slide

  49. micnncim/bitbrew
    ✔ Rich UI

    View full-size slide

  50. micnncim/bitbrew
    ✔ Installation

    View full-size slide

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

    View full-size slide

  52. @micnncim
    Thank you!

    View full-size slide