Skip to content

Commit c5fd64f

Browse files
committed
Rearchitecture to allow easier extensibility
1 parent 2f03a5a commit c5fd64f

File tree

14 files changed

+677
-75
lines changed

14 files changed

+677
-75
lines changed

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/

cmd/cleanup.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright © 2020 Mmadu Manasseh <[email protected]>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
// "fmt"
20+
21+
log "github.com/sirupsen/logrus"
22+
"github.com/spf13/cobra"
23+
24+
// "github.com/mensaah/reka/provider"
25+
"github.com/mensaah/reka/provider/aws"
26+
)
27+
28+
// cleanupCmd represents the cleanup command
29+
var cleanupCmd = &cobra.Command{
30+
Use: "cleanup",
31+
Short: "A brief description of your command",
32+
Long: `A longer description that spans multiple lines and likely contains examples
33+
and usage of using your command. For example:
34+
35+
Cobra is a CLI library for Go that empowers applications.
36+
This application is a tool to generate the needed files
37+
to quickly create a Cobra application.`,
38+
Run: func(cmd *cobra.Command, args []string) {
39+
provider := aws.NewProvider()
40+
log.Info("About to start getting Resources")
41+
resources := provider.GetAllResources()
42+
log.Info(resources)
43+
provider.DestroyResources(resources)
44+
},
45+
}
46+
47+
func init() {
48+
rootCmd.AddCommand(cleanupCmd)
49+
50+
// Here you will define your flags and configuration settings.
51+
52+
// Cobra supports Persistent Flags which will work for this command
53+
// and all subcommands, e.g.:
54+
// cleanupCmd.PersistentFlags().String("foo", "", "A help for foo")
55+
56+
// Cobra supports local flags which will only run when this command
57+
// is called directly, e.g.:
58+
// cleanupCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
59+
}

cmd/root.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
"github.com/spf13/cobra"
21+
"os"
22+
23+
homedir "github.com/mitchellh/go-homedir"
24+
"github.com/spf13/viper"
25+
)
26+
27+
var (
28+
cfgFile string
29+
provider string
30+
)
31+
32+
// rootCmd represents the base command when called without any subcommands
33+
var rootCmd = &cobra.Command{
34+
Use: "reka",
35+
Short: "A brief description of your application",
36+
Long: `A longer description that spans multiple lines and likely contains
37+
examples and usage of using your application. For example:
38+
39+
Cobra is a CLI library for Go that empowers applications.
40+
This application is a tool to generate the needed files
41+
to quickly create a Cobra application.`,
42+
// Uncomment the following line if your bare application
43+
// has an action associated with it:
44+
// Run: func(cmd *cobra.Command, args []string) { },
45+
}
46+
47+
// Execute adds all child commands to the root command and sets flags appropriately.
48+
// This is called by main.main(). It only needs to happen once to the rootCmd.
49+
func Execute() {
50+
if err := rootCmd.Execute(); err != nil {
51+
fmt.Println(err)
52+
os.Exit(1)
53+
}
54+
}
55+
56+
func init() {
57+
cobra.OnInitialize(initConfig)
58+
59+
// Here you will define your flags and configuration settings.
60+
// Cobra supports persistent flags, which, if defined here,
61+
// will be global for your application.
62+
63+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.reka.yaml)")
64+
65+
// Cobra also supports local flags, which will only run
66+
// when this action is called directly.
67+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
68+
}
69+
70+
// initConfig reads in config file and ENV variables if set.
71+
func initConfig() {
72+
if cfgFile != "" {
73+
// Use config file from the flag.
74+
viper.SetConfigFile(cfgFile)
75+
} else {
76+
// Find home directory.
77+
home, err := homedir.Dir()
78+
if err != nil {
79+
fmt.Println(err)
80+
os.Exit(1)
81+
}
82+
83+
// Search config in home directory with name ".reka" (without extension).
84+
viper.AddConfigPath(home)
85+
viper.SetConfigName(".reka")
86+
}
87+
88+
viper.AutomaticEnv() // read in environment variables that match
89+
90+
// If a config file is found, read it in.
91+
if err := viper.ReadInConfig(); err == nil {
92+
fmt.Println("Using config file:", viper.ConfigFileUsed())
93+
}
94+
}

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ module github.com/mensaah/reka
22

33
go 1.14
44

5-
require github.com/aws/aws-sdk-go-v2 v0.23.0
5+
require (
6+
github.com/aws/aws-sdk-go-v2 v0.23.0
7+
github.com/mitchellh/go-homedir v1.1.0
8+
github.com/sirupsen/logrus v1.2.0
9+
github.com/spf13/cobra v1.0.0
10+
github.com/spf13/viper v1.7.0
11+
)

0 commit comments

Comments
 (0)