-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
65 lines (56 loc) · 1.1 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
package main
import (
"fmt"
"os"
"strings"
"github.com/alecthomas/kong"
"github.com/fatih/color"
"github.com/spectralops/senv/pkg"
"github.com/spf13/viper"
)
var CLI struct {
Info bool `help:"Show information"`
Create bool `help:"Create global config"`
Config bool `help:"Path to config file"`
Cmd []string `arg optional name:"cmd" help:"Command to execute"`
}
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
kong.Parse(&CLI)
senv := pkg.Senv{
Cmd: CLI.Cmd,
}
senv.Init()
if CLI.Config {
configPath := senv.ConfigPath()
if len(configPath) > 0 {
fmt.Print(configPath)
os.Exit(0)
} else {
os.Exit(1)
}
}
if CLI.Info {
blue := color.New(color.FgBlue).SprintFunc()
configPath := senv.ConfigPath()
if len(configPath) > 0 {
fmt.Printf("%v\n%v\n\n", blue("[config]"), viper.ConfigFileUsed())
}
fmt.Printf("%v\n%v\n", blue("[redact]"), strings.Join(senv.RedactList(), "\n"))
os.Exit(1)
}
if CLI.Create {
senv.CreateConfig()
os.Exit(0)
}
cmd := CLI.Cmd
if len(cmd) > 0 {
senv.Exec()
} else {
senv.Print()
}
}