@@ -5,43 +5,27 @@ Copyright © 2022 NAME HERE <EMAIL ADDRESS>
5
5
package cmd
6
6
7
7
import (
8
+ "fmt"
8
9
"os"
9
10
10
11
"github.com/spf13/cobra"
11
12
)
12
13
13
14
// rootCmd represents the base command when called without any subcommands
14
- var rootCmd = & cobra.Command {
15
- Use : "go-cat" ,
16
- Short : "A brief description of your application" ,
17
- Long : `A longer description that spans multiple lines and likely contains
18
- examples and usage of using your application. For example:
19
-
20
- Cobra is a CLI library for Go that empowers applications.
21
- This application is a tool to generate the needed files
22
- to quickly create a Cobra application.` ,
23
- // Uncomment the following line if your bare application
24
- // has an action associated with it:
25
- // Run: func(cmd *cobra.Command, args []string) { },
15
+ func NewRoodCmd () * cobra.Command {
16
+ return & cobra.Command {
17
+ Use : "go-cat" ,
18
+ Short : "Go implementation of cat" ,
19
+ Long : `Works like cat` ,
20
+ Run : func (cmd * cobra.Command , args []string ) {
21
+ },
22
+ }
26
23
}
27
24
28
- // Execute adds all child commands to the root command and sets flags appropriately.
29
- // This is called by main.main(). It only needs to happen once to the rootCmd.
30
25
func Execute () {
31
- err := rootCmd .Execute ()
32
- if err != nil {
26
+ rootCmd := NewRoodCmd ()
27
+ if err := rootCmd .Execute (); err != nil {
28
+ fmt .Fprintln (os .Stderr , err )
33
29
os .Exit (1 )
34
30
}
35
31
}
36
-
37
- func init () {
38
- // Here you will define your flags and configuration settings.
39
- // Cobra supports persistent flags, which, if defined here,
40
- // will be global for your application.
41
-
42
- // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.go-cat.yaml)")
43
-
44
- // Cobra also supports local flags, which will only run
45
- // when this action is called directly.
46
- rootCmd .Flags ().BoolP ("toggle" , "t" , false , "Help message for toggle" )
47
- }
0 commit comments