Get Go and - most importantly - install the great golangci-lint and follow the advice of their "Bug Gopher"!
$ go get -u github.com/spf13/cobra@latest $ cobra-cli init --author "Till Kuhn" Your Cobra application is ready at /Users/tillkuhn/git/hub/letitgo $ go run main.go A longer description that spans multiple lines and likely contains
Example to add a 'serve' command, this creates a file
cmd/server.go$ cobra-cli add serve serve created at /Users/tillkuhn/git/hub/letitgo
Create a dedicated folder / package with at least one .go file for your experiments
$ mkdir charts && echo "package charts" >charts/charts.go
printf "package charts\n\nfunc Run() {}" >charts/charts.go
Open ./cmd/<command>.go and call a public function from your new package
var chartsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("charts called")
charts.Run() // Delegate to package function (1st entry point)
// (...)
main() in main.go delegates to Cobra’s Execute() function in cmd/root.go$ cat main.go
func main() {
cmd.Execute()
}
Run your new command For frequently used command, create a dedicated target in
Makefile$ go run main.go serve Running server
$ go get "github.com/kelseyhightower/envconfig" go get: added github.com/kelseyhightower/envconfig v1.4.0
