root.go - boof - AWS EC2 instance tag searching in golang, no longer used.
(HTM) git clone git://jay.scot/boof
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
root.go (1003B)
---
1 package cmd
2
3 import (
4 "fmt"
5 "os"
6
7 "github.com/spf13/cobra"
8
9 homedir "github.com/mitchellh/go-homedir"
10 "github.com/spf13/viper"
11 )
12
13 var cfgFile string
14
15 var rootCmd = &cobra.Command{
16 Use: "boof",
17 Short: "Search AWS services based on tag.",
18 Long: `This application allows you to search AWS services based on tags, by
19 default this is configured to search on the Name tag.`,
20 }
21
22 func Execute() {
23 if err := rootCmd.Execute(); err != nil {
24 fmt.Println(err)
25 os.Exit(1)
26 }
27 }
28
29 func init() {
30 cobra.OnInitialize(initConfig)
31
32 rootCmd.Flags().String("tag", "Name", "The tag to search on")
33 }
34
35 func initConfig() {
36 if cfgFile != "" {
37 viper.SetConfigFile(cfgFile)
38 } else {
39 home, err := homedir.Dir()
40 if err != nil {
41 fmt.Println(err)
42 os.Exit(1)
43 }
44
45 viper.AddConfigPath(home)
46 viper.SetConfigName(".boof")
47 }
48
49 viper.AutomaticEnv() // read in environment variables that match
50
51 if err := viper.ReadInConfig(); err == nil {
52 fmt.Println("Using config file:", viper.ConfigFileUsed())
53 }
54 }