Lesson 23 of 60
GoBuilding a CLI with Cobra
20 minutes
Course progress38%
Cobra CLI Framework
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
Cobra powers kubectl, git, and many other tools.
package main
import (
"fmt"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{ Use: , Short: }
helloCmd = &cobra.Command{
Use: ,
Short: ,
Args: cobra.ExactArgs(),
Run: {
fmt.Printf(, args[])
},
}
{ rootCmd.AddCommand(helloCmd) }
{ rootCmd.Execute() }