-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
executable file
·60 lines (47 loc) · 1.25 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
Version string
Commit string
Date string
debug bool
startTime = time.Now()
)
func getRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "notion-cli",
Short: "notion is a command line tool for interacting with the Notion API",
// Needs to exist to make --version work
Run: func(cmd *cobra.Command, args []string) {},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if version, _ := cmd.Flags().GetBool("version"); version {
fmt.Printf("Version: %s\nCommit: %s\nDate: %s\n", Version, Commit, Date)
os.Exit(0)
}
if debug, _ = cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
},
}
cmd.PersistentFlags().Bool("version", false, "Print the version of the CLI")
cmd.PersistentFlags().Bool("debug", false, "Enable debug logging")
return cmd
}
func Execute() {
logrus.SetOutput(os.Stderr)
rootCmd := getRootCmd()
rootCmd.AddCommand(getDBIssueCmd())
rootCmd.AddCommand(getDBIssueDetailCmd())
rootCmd.AddCommand(getMaintenanceCmd())
if err := rootCmd.Execute(); err != nil {
logrus.Error(err)
os.Exit(1)
}
logrus.Debugf("Execution took: %s", time.Since(startTime))
}