Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building CLI Applications with Golang

513 views

Published on

Lightening Talk on building cli application with Golang

Published in: Internet
  • Be the first to comment

Building CLI Applications with Golang

  1. 1. Developing CLI Apps with Golang Anshul Patel
  2. 2. Why Golang for CLI? ● Cross Platform Compilation. (Windows, Linux, Mac, BSD, Solaris) ● Dependencies can be statically linked & packaged into single binary. ● Execution performance is close to C/C++. ● Popular CLI Apps in Golang: ○ Packer ○ Terraform ○ Consul ○ Kubernetes ○ Prometheus ○ Docker ○ Hugo ○ etcd
  3. 3. CLI Structure ● Appname: Name of App ● Subcommand: Represents action ● Flags: Modifiers for action ● Arguments: Input on which actions will be applied. Example:
  4. 4. Why CLI Framework? ● Provides libs/functions/boilerplate for following: ○ Subcommands and nested subcommands. (e.g. git clone/pull/push) ○ POSIX compliant flags. (e.g. git clone -q/--quiet) ○ Ability to generate help documentation from the comments. (e.g. git clone/pull -- help) ○ Ability to generate man pages. (man git) ○ Ability to generate bash autocomplete. (/etc/bash_completion.d/) ○ Intelligent suggestions. (git clne → Did you mean this ? → git clone) ○ Provide inline and configuration file support. ($HOME/.app.yaml)
  5. 5. Popular Golang CLI Frameworks ● spf13/Cobra ● urfave/cli ● docopt/docopt.go ● mitchellh/cli
  6. 6. Cobra CLI Framework Development Flow
  7. 7. Thank You! References ● https://github.com/spf13/cobra ● https://github.com/avelino/awesome-go ● https://github.com/anshulpatel25/calccli-go

×