Skip to content

Commit 6d31a6b

Browse files
committed
fix version and creating config file dir
1 parent 2fed4f7 commit 6d31a6b

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

cmd/local_cmd.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
var (
6+
localCmd = &cobra.Command{
7+
Use: "local",
8+
Aliases: []string{"\"kubectl tf(o)\""},
9+
Short: "Use tfo with a local kubeconfig",
10+
Args: cobra.MaximumNArgs(0),
11+
}
12+
)
13+
14+
func init() {
15+
rootCmd.AddCommand(localCmd)
16+
}

cmd/debug_local_cmd.go cmd/local_debug_cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var debugCmd = &cobra.Command{
3030
}
3131

3232
func init() {
33-
rootCmd.AddCommand(debugCmd)
33+
localCmd.AddCommand(debugCmd)
3434
}
3535

3636
func debug(name string) {

cmd/show_cmd.go cmd/local_show_cmd.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ var showCmd = &cobra.Command{
2424

2525
func init() {
2626
showCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "Show tfo resources for all namespaces")
27-
rootCmd.AddCommand(showCmd)
27+
//
28+
// TODO the show command is broken and needs works. Perhaps "show" should be "list"
29+
// Other ideas might be that "list tf" to lists the terraform resources (ie kubectl get tf)
30+
// and "list pods" would be what "show" was supposed to do. Anyways, for now I'm going to abandon ship here.
31+
//
32+
// localCmd.AddCommand(showCmd)
2833
}
2934

3035
func show(name string, allNamespaces, showPrevious bool) {

cmd/root_cmd.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ type Session struct {
6262
}
6363

6464
func newSession() {
65-
kubeConfig, _ := clientcmd.BuildConfigFromFlags("", kubeconfig)
66-
// if err != nil {
67-
// panic(err)
68-
// }
6965

7066
viper.SetEnvPrefix("TFO")
7167
viper.AutomaticEnv()
@@ -101,7 +97,6 @@ func newSession() {
10197
}
10298

10399
if readErr := viper.ReadInConfig(); readErr != nil {
104-
105100
err := createConfigFile(tfoConfigFile)
106101
if err != nil {
107102
log.Print(err)
@@ -112,6 +107,7 @@ func newSession() {
112107
// Config file found and successfully parsed
113108

114109
// Get the namespace from the user's contexts when not passed in via flag
110+
kubeConfig, _ := clientcmd.BuildConfigFromFlags("", kubeconfig)
115111
if kubeConfig != nil && namespace == "" {
116112
// Define the schema of the kubeconfig that is meaningful to extract
117113
// the current-context's namespace (if defined)
@@ -211,6 +207,10 @@ func createConfigFile(name string) error {
211207
if !create {
212208
return fmt.Errorf("select a config file with `--config`")
213209
}
210+
err = os.MkdirAll(filepath.Dir(name), 0755)
211+
if err != nil {
212+
return fmt.Errorf("failed to create dir: %s", err)
213+
}
214214
_, err = os.Create(name)
215215
return err
216216

main.go

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"fmt"
5+
"os"
6+
47
"github.com/isaaguilar/terraform-operator-cli/cmd"
58
)
69

@@ -9,3 +12,18 @@ var version string
912
func main() {
1013
cmd.Execute(version)
1114
}
15+
16+
func init() {
17+
if version == "" {
18+
version = "v0.0.0"
19+
}
20+
// Hijack the version sub-command. This prevents version from initializing
21+
// cobra. When more than a single arg of "version" is called,
22+
// cobra's version implementation will be processed.
23+
if len(os.Args) == 2 {
24+
if os.Args[1] == "version" {
25+
fmt.Println(version)
26+
os.Exit(0)
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)