/
root.go
41 lines (33 loc) · 840 Bytes
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package commands
import (
"io"
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var v string
func NewRootCommand() *cobra.Command {
rootCmd := &cobra.Command{
Use: "drone-workshopper",
Short: "An helper to interact and configure Gitea using its REST API",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := logSetup(os.Stdout, v); err != nil {
return err
}
return nil
},
}
rootCmd.PersistentFlags().StringVarP(&v, "verbose", "v", log.WarnLevel.String(), "The logging level to set")
rootCmd.AddCommand(NewVersionCommand())
rootCmd.AddCommand(NewWorkshopSetupCommand())
return rootCmd
}
func logSetup(out io.Writer, level string) error {
log.SetOutput(out)
lvl, err := log.ParseLevel(level)
if err != nil {
return err
}
log.SetLevel(lvl)
return nil
}