-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
55 lines (42 loc) · 1.23 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
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/ArcadiaPower/axolotl/cli"
"github.com/spf13/viper"
"github.com/alecthomas/kingpin"
)
// Version is provided at compile time
var Version = "devel"
func init() {
// initialize viper config
configName := "config"
configType := "yaml"
configPath := os.ExpandEnv("${HOME}/.config/ax")
viper.AddConfigPath(configPath)
viper.SetConfigName(configName)
viper.SetConfigType(configType)
// set default values
viper.SetDefault("autoGimmeAwsCreds", true)
viper.SetDefault("defaultRegion", "us-east-1")
configFile := filepath.Join(configPath, fmt.Sprintf("%s.%s", configName, configType))
if _, err := os.Stat(configFile); os.IsNotExist(err) {
// create configPath directory
if err := os.MkdirAll(configPath, 0755); err != nil {
log.Fatalf("error creating config directory: %s", err.Error())
}
if err := viper.SafeWriteConfig(); err != nil {
log.Fatalf("error writing config file: %s", err.Error())
}
}
}
func main() {
app := kingpin.New("ax", "A helper utility for switching AWS profiles in subshells.")
app.Version(Version)
a := cli.ConfigureGlobals(app)
cli.ConfigureExecCommand(app, a)
_, err := app.Parse(os.Args[1:])
kingpin.FatalIfError(err, "")
}