Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Fix up config
Browse files Browse the repository at this point in the history
  • Loading branch information
EngHabu committed Jun 4, 2020
1 parent 86951ad commit 0da0dae
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .idea/$CACHE_FILE$

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/dictionaries

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/flytectl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package config

import "github.com/lyft/flytestdlib/config"

//go:generate pflags Config

var (
defaultConfig = &Config{}
section = config.MustRegisterSection("root", defaultConfig)
)

type Config struct {
Project string `json:"project" pflag:",Specifies the project to work on."`
Domain string `json:"domain" pflag:",Specified the domain to work on."`
}

func GetConfig() *Config {
return section.GetConfig().(*Config)
}
47 changes: 47 additions & 0 deletions cmd/config/config_flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 146 additions & 0 deletions cmd/config/config_flags_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ package cmd
import (
"context"

"github.com/lyft/flytestdlib/config"
"github.com/lyft/flytectl/cmd/config"

stdConfig "github.com/lyft/flytestdlib/config"
"github.com/lyft/flytestdlib/config/viper"
"github.com/spf13/cobra"
)

var (
cfgFile string
configAccessor = viper.NewAccessor(config.Options{StrictMode: true})
configAccessor = viper.NewAccessor(stdConfig.Options{StrictMode: true})
)

type persistentFlags struct {
Project *string
Domain *string
}

func newRootCmd() *cobra.Command {
persistentFlags := persistentFlags{}
rootCmd := &cobra.Command{
PersistentPreRunE: initConfig,
}
Expand All @@ -29,15 +25,20 @@ func newRootCmd() *cobra.Command {

configAccessor.InitializePflags(rootCmd.PersistentFlags())

persistentFlags.Project = rootCmd.PersistentFlags().String("project", "", "Specifies the Flyte project.")
persistentFlags.Domain = rootCmd.PersistentFlags().String("domain", "", "Specifies the Flyte project's domain.")
// Due to https://github.com/lyft/flyte/issues/341, project flag will have to be specified as
// --root.project, this adds a convenience on top to allow --project to be used
rootCmd.PersistentFlags().StringVarP(&(config.GetConfig().Project), "project", "p", "", "Specifies the Flyte project.")
rootCmd.PersistentFlags().StringVarP(&(config.GetConfig().Domain), "domain", "d", "", "Specifies the Flyte project's domain.")

rootCmd.AddCommand(viper.GetConfigCommand())
rootCmd.AddCommand(versionCmd)
config.GetConfig()

rootCmd.AddCommand(newTimelineCmd(persistentFlags))
return rootCmd
}

func initConfig(_ *cobra.Command, _ []string) error {
configAccessor = viper.NewAccessor(config.Options{
configAccessor = viper.NewAccessor(stdConfig.Options{
StrictMode: true,
SearchPaths: []string{cfgFile},
})
Expand Down
3 changes: 2 additions & 1 deletion cmd/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
admin:
endpoint: dns:///flyte.lyft.net
endpoint: http://localhost:30082
insecure: true
20 changes: 20 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/lyft/flytectl/cmd/config"
"github.com/lyft/flytestdlib/logger"
"github.com/lyft/flytestdlib/version"
"github.com/spf13/cobra"
)

var (
versionCmd = &cobra.Command{
Use: "version",
Short: "Displays version information for the client and server.",
Run: func(cmd *cobra.Command, args []string) {
version.LogBuildInformation("flytectl")
logger.InfofNoCtx(config.GetConfig().Project)
logger.InfofNoCtx(config.GetConfig().Domain)
},
}
)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/lyft/flytestdlib v0.2.31
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.4.0
github.com/wcharczuk/go-chart v2.0.1+incompatible
Expand Down

0 comments on commit 0da0dae

Please sign in to comment.