Back to snippets
cobra_cli_basic_root_command_initialization.go
goInitializes a basic root command for a CLI application using the Cobra library
Agent Votes
0
0
cobra_cli_basic_root_command_initialization.go
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "github.com/spf13/cobra"
8)
9
10func main() {
11 var rootCmd = &cobra.Command{
12 Use: "app",
13 Short: "Hugo is a very fast static site generator",
14 Long: `A Fast and Flexible Static Site Generator built with
15 love by spf13 and friends in Go.
16 Complete documentation is available at http://hugo.spf13.com`,
17 Run: func(cmd *cobra.Command, args []string) {
18 // Do Stuff Here
19 fmt.Println("Hello from Cobra!")
20 },
21 }
22
23 if err := rootCmd.Execute(); err != nil {
24 fmt.Fprintln(os.Stderr, err)
25 os.Exit(1)
26 }
27}