Skip to content

Commit

Permalink
added support for switching between dev and prod configs; bumped vers…
Browse files Browse the repository at this point in the history
…ion to 0.5.5
  • Loading branch information
ogazitt committed Jun 29, 2020
1 parent 9a16774 commit c8f1ae1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
48 changes: 48 additions & 0 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,58 @@ var configSetCmd = &cobra.Command{
},
}

// configSetDevCmd represents the config set "dev" command
var configSetDevCmd = &cobra.Command{
Use: "dev",
Short: "Set config information to dev environment",
Long: `Set config information to dev environment.`,
Run: func(cmd *cobra.Command, args []string) {
viper.Set("ClientID", "f9BSuAhmF8dmUtJWZyjAVJbGJWQMKsMW")
viper.Set("APIURL", "https://dev.snapmaster.io")
viper.Set("AuthDomain", "snapmaster-dev.auth0.com")

// use viper to write the config to the file
err := viper.WriteConfig()
if err != nil {
fmt.Printf("snap: could not write config file\nerror: %s\n", err)
os.Exit(1)
} else {
fmt.Printf("snap: updated config\n")
}

printConfig()
},
}

// configSetProdCmd represents the config set "prod" command
var configSetProdCmd = &cobra.Command{
Use: "prod",
Short: "Set config information to production environment",
Long: `Set config information to production environment.`,
Run: func(cmd *cobra.Command, args []string) {
viper.Set("ClientID", "O4e0z2Ky5DSvjzw3N5YLgtrz1GGltkOb")
viper.Set("APIURL", "https://www.snapmaster.io")
viper.Set("AuthDomain", "snapmaster.auth0.com")

// use viper to write the config to the file
err := viper.WriteConfig()
if err != nil {
fmt.Printf("snap: could not write config file\nerror: %s\n", err)
os.Exit(1)
} else {
fmt.Printf("snap: updated config\n")
}

printConfig()
},
}

func init() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(configGetCmd)
configCmd.AddCommand(configSetCmd)
configSetCmd.AddCommand(configSetDevCmd)
configSetCmd.AddCommand(configSetProdCmd)

configSetCmd.Flags().StringP("api-url", "", "", "API URL (defaults to https://dev.snapmaster.io)")
configSetCmd.Flags().StringP("client-id", "", "", "Auth0 Client ID (required for any non-default API URL)")
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func init() {
// initConfig reads in config file and ENV variables if set.
func initConfig() {
// set some default values
viper.SetDefault("ClientID", "f9BSuAhmF8dmUtJWZyjAVJbGJWQMKsMW")
viper.SetDefault("APIURL", "https://dev.snapmaster.io")
viper.SetDefault("AuthDomain", "snapmaster-dev.auth0.com")
viper.SetDefault("ClientID", "O4e0z2Ky5DSvjzw3N5YLgtrz1GGltkOb")
viper.SetDefault("APIURL", "https://www.snapmaster.io")
viper.SetDefault("AuthDomain", "snapmaster.auth0.com")
viper.SetDefault("RedirectURL", "http://localhost:8085")

if cfgFile != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package version

// Version number
var Version string = "0.5.4"
var Version string = "0.5.5"

// GitHash of the last commit
var GitHash string

0 comments on commit c8f1ae1

Please sign in to comment.