-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add crda config commands (#50)
* add crda config commands * go tests
- Loading branch information
Deepak Sharma
authored
Apr 26, 2021
1 parent
ba93c2f
commit 4bc0b72
Showing
12 changed files
with
155 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// configCmd represents the config command | ||
var configCmd = &cobra.Command{ | ||
Use: "config SUBCOMMAND [flags]", | ||
Short: "Modify crda configuration", | ||
Long: `Modify crda configuration`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Help() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(configCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// getCmd represents the get command | ||
var getCmd = &cobra.Command{ | ||
Use: "get CONFIG-KEY", | ||
Short: "Get active crda configurations", | ||
Long: `Get active crda configurations`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) < 1 { | ||
c := viper.AllSettings() | ||
bs, err := yaml.Marshal(c) | ||
if err != nil { | ||
log.Error().Msgf("unable to marshal config to YAML") | ||
return err | ||
} | ||
fmt.Println(string(bs)) | ||
return nil | ||
} | ||
key := args[0] | ||
v := viper.IsSet(args[0]) | ||
if !v { | ||
return fmt.Errorf("configuration property '%s' does not exist", key) | ||
} | ||
value := viper.Get(args[0]) | ||
fmt.Println(key, ":", value) | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
configCmd.AddCommand(getCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fabric8-analytics/cli-tools/pkg/config" | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// setCmd represents the set command | ||
var setCmd = &cobra.Command{ | ||
Use: "set CONFIG-KEY VALUE", | ||
Short: "Set a crda configuration property", | ||
Long: `Sets a crda configuration property`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) < 2 { | ||
log.Error().Msgf("please provide a configuration property and its value as in 'crda config set CONFIG-KEY VALUE'") | ||
return | ||
} | ||
viper.Set(args[0], args[1]) | ||
err := viper.WriteConfig() | ||
if err != nil { | ||
log.Error().Msgf("unable to write config health") | ||
return | ||
} | ||
value := viper.Get(args[0]) | ||
config.ViperUnMarshal() | ||
if value != args[1] { | ||
log.Error().Msgf("unable to set configuration value") | ||
return | ||
} | ||
fmt.Println("successfully set configuration value") | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
configCmd.AddCommand(setCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters