Skip to content

Commit

Permalink
chore(config): Simplify Kubeconfig flag default value
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 25, 2023
1 parent ebe26f4 commit 5541b78
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
11 changes: 5 additions & 6 deletions internal/config/flags/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ import (
const KubeconfigEnv = "KUBECONFIG"

func Kubeconfig(cmd *cobra.Command) {
kubeconfigEnv := os.Getenv(KubeconfigEnv)
if kubeconfigEnv == "" {
kubeconfigEnv = filepath.Join("$HOME", ".kube", "config")
}

cmd.PersistentFlags().String(consts.KubeconfigFlag, kubeconfigEnv, "Paths to the kubeconfig file")
cmd.PersistentFlags().String(consts.KubeconfigFlag, filepath.Join("$HOME", ".kube", "config"), "Paths to the kubeconfig file")
}

func BindKubeconfig(cmd *cobra.Command) {
if err := viper.BindPFlag(consts.KubeconfigKey, cmd.Flags().Lookup(consts.KubeconfigFlag)); err != nil {
panic(err)
}

if env := os.Getenv(KubeconfigEnv); env != "" {
viper.SetDefault(consts.KubeconfigKey, env)
}
}

func Context(cmd *cobra.Command) {
Expand Down
5 changes: 0 additions & 5 deletions internal/generate/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

"github.com/clevyr/kubedb/cmd"
"github.com/clevyr/kubedb/internal/config/flags"
"github.com/spf13/cobra/doc"
)

Expand All @@ -24,10 +23,6 @@ func main() {
log.Fatal(fmt.Errorf("failed to mkdir: %w", err))
}

if err := os.Setenv(flags.KubeconfigEnv, ""); err != nil {
log.Fatal(err)
}

rootCmd := cmd.NewCommand()

err = doc.GenMarkdownTree(rootCmd, output)
Expand Down
5 changes: 0 additions & 5 deletions internal/generate/manpages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/clevyr/kubedb/cmd"
kubedbFlags "github.com/clevyr/kubedb/internal/config/flags"
gzip "github.com/klauspost/pgzip"
"github.com/spf13/cobra/doc"
flag "github.com/spf13/pflag"
Expand All @@ -36,10 +35,6 @@ func main() {
panic(err)
}

if err := os.Setenv(kubedbFlags.KubeconfigEnv, ""); err != nil {
panic(err)
}

rootCmd := cmd.NewCommand()
rootName := rootCmd.Name()

Expand Down

0 comments on commit 5541b78

Please sign in to comment.