Skip to content

Commit

Permalink
feat: add secrets config helper
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <[email protected]>
  • Loading branch information
gfanton committed Jun 20, 2024
1 parent ef5bb4b commit ac17ef4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gno.land/cmd/gnoland/config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newConfigGetCmd(io commands.IO) *commands.Command {
TagNameSelector: "json",
TreeDisplay: true,
}
subs := generateSubCommandHelper(helperGen, func(_ context.Context, args []string) error {
subs := generateSubCommandHelper(helperGen, config.Config{}, func(_ context.Context, args []string) error {
return execConfigGet(cfg, io, args)
})

Expand Down
7 changes: 3 additions & 4 deletions gno.land/cmd/gnoland/config_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"unicode"

"github.com/gnolang/gno/tm2/pkg/bft/config"
"github.com/gnolang/gno/tm2/pkg/commands"
)

Expand All @@ -20,8 +19,8 @@ type metadataHelperGenerator struct {
TreeDisplay bool
}

func generateSubCommandHelper(gen metadataHelperGenerator, exec commands.ExecMethod) []*commands.Command {
rv := reflect.ValueOf(config.Config{})
func generateSubCommandHelper(gen metadataHelperGenerator, s any, exec commands.ExecMethod) []*commands.Command {
rv := reflect.ValueOf(s)
metas := gen.generateFields(rv, "", 0)

cmds := make([]*commands.Command, len(metas))
Expand Down Expand Up @@ -67,7 +66,7 @@ func (g *metadataHelperGenerator) generateFields(rv reflect.Value, parent string
name := field.Name
// Get JSON tag name
if g.TagNameSelector != "" {
name = field.Tag.Get(g.TagNameSelector)
name, _, _ = strings.Cut(field.Tag.Get(g.TagNameSelector), ",")
if name == "" || name == "-" {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion gno.land/cmd/gnoland/config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newConfigSetCmd(io commands.IO) *commands.Command {
TagNameSelector: "json",
TreeDisplay: true,
}
cmd.AddSubCommands(generateSubCommandHelper(helperGen, func(_ context.Context, args []string) error {
cmd.AddSubCommands(generateSubCommandHelper(helperGen, config.Config{}, func(_ context.Context, args []string) error {
return execConfigEdit(cfg, io, args)
})...)

Expand Down
12 changes: 12 additions & 0 deletions gno.land/cmd/gnoland/secrets_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ func newSecretsGetCmd(io commands.IO) *commands.Command {
},
)

// Add subcommand helpers
helperGen := metadataHelperGenerator{
MetaUpdate: func(meta *commands.Metadata) {
meta.ShortUsage = "secrets get " + meta.Name
},
TagNameSelector: "json",
TreeDisplay: false,
}
cmd.AddSubCommands(generateSubCommandHelper(helperGen, secrets{}, func(_ context.Context, args []string) error {
return execSecretsGet(cfg, args, io)
})...)

return cmd
}

Expand Down

0 comments on commit ac17ef4

Please sign in to comment.