-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (58 loc) · 1.62 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
package main
import (
"context"
"errors"
"os"
"path"
"github.com/robgonnella/ops/cli/commands"
app_info "github.com/robgonnella/ops/internal/app-info"
"github.com/robgonnella/ops/internal/event"
"github.com/robgonnella/ops/internal/logger"
"github.com/robgonnella/ops/internal/ui"
"github.com/spf13/viper"
)
/**
* Main entry point for all commands
* Here we setup environment config via viper
*/
func setRuntTimeConfig() error {
userHomeDir, err := os.UserHomeDir()
if err != nil {
return err
}
configDir := path.Join(userHomeDir, ".config", app_info.NAME)
if err := os.MkdirAll(configDir, 0755); err != nil && !errors.Is(err, os.ErrExist) {
return err
}
logFile := path.Join(configDir, app_info.NAME+".log")
configFile := path.Join(configDir, "config.json")
defaultSSHIdentity := path.Join(userHomeDir, ".ssh", "id_rsa")
user := os.Getenv("USER")
// share run-time config globally using viper
viper.Set("log-file", logFile)
viper.Set("config-dir", configDir)
viper.Set("config-path", configFile)
viper.Set("default-ssh-identity", defaultSSHIdentity)
viper.Set("user", user)
return nil
}
// Entry point for the cli
func main() {
log := logger.New()
err := setRuntTimeConfig()
if err != nil {
log.Fatal().Err(err).Msg("")
}
eventManager := event.NewEventManager()
appUI := ui.NewUI()
// Get the "root" cobra cli command
cmd := commands.Root(&commands.CommandProps{
UI: appUI,
EventManager: eventManager,
})
// execute the cobra command and exit with error code if necessary
err = cmd.ExecuteContext(context.Background())
if err != nil {
log.Fatal().Err(err).Msg("")
}
}