Skip to content

Commit

Permalink
fix: get kv list not work with label
Browse files Browse the repository at this point in the history
  • Loading branch information
ifooth committed Dec 28, 2023
1 parent 52fd84a commit 7c61cca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 11 additions & 9 deletions cmd/bscp/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ var (
Use: "get",
Short: "Display app or kv resources",
Long: `Display app or kv resources`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// 设置日志等级, get 命令默认是 error
if logLevel == "" {
logLevel = "error"
}

level := logger.GetLevelByName(logLevel)
logger.SetLevel(level)

// 校验&反序列化 labels
if labelsStr != "" {
if err := json.Unmarshal([]byte(labelsStr), &labels); err != nil {
return fmt.Errorf("invalid labels: %w", err)
}
}

return nil
},
}

Expand Down Expand Up @@ -135,7 +144,7 @@ func runGetApp(args []string) error {
}

func runGetListKv(bscp client.Client, app string, match []string) error {
release, err := bscp.PullKvs(app, match)
release, err := bscp.PullKvs(app, match, client.WithAppLabels(labels))
if err != nil {
return err
}
Expand Down Expand Up @@ -169,13 +178,6 @@ func runGetListKv(bscp client.Client, app string, match []string) error {
}

func runGetKvValue(bscp client.Client, app, key string) error {
labels := map[string]string{}
if labelsStr != "" {
if err := json.Unmarshal([]byte(labelsStr), &labels); err != nil {
return fmt.Errorf("labels invalid: %w", err)
}
}

value, err := bscp.Get(app, key, client.WithAppLabels(labels))
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion cmd/bscp/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ var (
Use: "bscp",
Short: "bscp is a command line tool for blueking service config platform",
Long: `bscp is a command line tool for blueking service config platform`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// 设置日志等级
level := logger.GetLevelByName(logLevel)
logger.SetLevel(level)

return nil
},
}
)
Expand Down

0 comments on commit 7c61cca

Please sign in to comment.