-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (70 loc) · 2.18 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/mitchellh/colorstring"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/yodamad/heimdall/cmd"
"github.com/yodamad/heimdall/commons"
"github.com/yodamad/heimdall/utils"
"os"
)
// ldflags vars
var (
version = "dev"
commit = "none"
date = "unknown"
)
var rootCmd = &cobra.Command{
Use: "heimdall",
Short: colorstring.Color("[yellow]Heimdall[default] helps you with your git folders"),
Long: colorstring.Color(`
[yellow]Heimdall[default] is a CLI tool to help you with your git folders.
You can check, update, ... everything easily
`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
utils.PrintBanner()
},
Example: colorstring.Color("[light_blue]heimdall -h"),
}
func init() {
commons.Version = version
commons.Commit = commit
commons.Date = date
rootCmd.AddCommand(cmd.GitInfo)
rootCmd.AddCommand(cmd.GitClone)
rootCmd.PersistentFlags().BoolVarP(&commons.Verbose, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().StringVarP(&commons.LogDir, "log-dir", "l", commons.DefaultFolder, "log directory")
rootCmd.PersistentFlags().StringVarP(&commons.WorkDir, "work-dir", "w", commons.DefaultWorkDir, "work directory")
rootCmd.PersistentFlags().StringVarP(&commons.InputConfigFile, "config-file", "c", commons.InputConfigFile, "config file")
// Init .heimdall folder
_, err := os.Stat(commons.DefaultFolder)
if os.IsNotExist(err) {
err := os.Mkdir(commons.DefaultFolder, os.ModePerm)
if err != nil {
fmt.Errorf("Cannot create dir " + err.Error())
commons.DefaultFolder = os.TempDir()
}
}
log.SetFormatter(&log.TextFormatter{
DisableLevelTruncation: true,
})
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
f, _ := os.OpenFile(commons.DefaultFolder+"heimdall.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
log.SetOutput(f)
// Only log the warning severity or above.
log.SetLevel(log.InfoLevel)
rootCmd.SetHelpTemplate(commons.HelpMessageTemplate)
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
utils.OverrideLogFile()
fmt.Println(err)
os.Exit(1)
}
}
func main() {
Execute()
}