var rootCmd = &cobra.Command{ Use: "mycli", Short: "MyCLI is a simple CLI application", Long: `MyCLI is a simple CLI application for demonstrating how to build CLI applications using Cobra.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Welcome to MyCLI!") }, }
// Execute executes the root command. funcExecute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } }
funcinit() { // Define global flags for the root command rootCmd.PersistentFlags().StringP("config", "c", "", "config file (default is $HOME/.mycli.yaml)") }