var versionCmd = &cobra.Command{ Use: "version", Short: "Print the application version", Long: `All software has versions. This is the application's.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Application version: v1.0.0") }, }
var listCmd = &cobra.Command{ Use: "list", Short: "List items", Long: `Print a list of items from the database.`, Run: func(cmd *cobra.Command, args []string) { items := database.ReadAllItems() for _, item := range items { fmt.Println(item) } }, }In this example, the 'Run' function of the 'listCmd' retrieves a list of items from the 'database' package and prints them one by one using the 'fmt.Println' function. In summary, the Command Out feature of the github.com/spf13/cobra package library allows Go applications to print output to the terminal. The examples shown here demonstrate how it can be used to print the application version and a list of items.