Skip to content

Commit

Permalink
chore: add comments & type display for getter/setter
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
  • Loading branch information
gfanton committed Aug 7, 2024
1 parent acc328c commit 25b3dc3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func newConfigGetCmd(io commands.IO) *commands.Command {

// Add subcommand helpers
helperGen := metadataHelperGenerator{
MetaUpdate: func(meta *commands.Metadata) {
meta.ShortUsage = "config get " + meta.Name
MetaUpdate: func(meta *commands.Metadata, inputType string) {
meta.ShortUsage = fmt.Sprintf("config get %s <%s>", meta.Name, inputType)
},
TagNameSelector: "json",
TreeDisplay: true,
Expand Down
9 changes: 7 additions & 2 deletions gno.land/cmd/gnoland/config_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (

type metadataHelperGenerator struct {
// Optional callback to edit metadata
MetaUpdate func(*commands.Metadata)
MetaUpdate func(meta *commands.Metadata, inputType string)
// Tag to select for name, if empty will use the field Name
TagNameSelector string
// Will display description with tree representation
TreeDisplay bool
}

// generateSubCommandHelper generates subcommands based on `s` structure fields and their respective tag descriptions
func generateSubCommandHelper(gen metadataHelperGenerator, s any, exec commands.ExecMethod) []*commands.Command {
rv := reflect.ValueOf(s)
metas := gen.generateFields(rv, "", 0)
Expand Down Expand Up @@ -108,10 +109,14 @@ func (g *metadataHelperGenerator) generateFields(rv reflect.Value, parent string

// Display full comment as Long Help
meta.LongHelp = comment
} else {
// If the comment is empty, it mostly means that there is no help.
// Use a blank space to avoid falling back on short help.
meta.LongHelp = " "
}

if g.MetaUpdate != nil {
g.MetaUpdate(&meta)
g.MetaUpdate(&meta, field.Type.String())
}

metas = append(metas, meta)
Expand Down
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func newConfigSetCmd(io commands.IO) *commands.Command {

// Add subcommand helpers
helperGen := metadataHelperGenerator{
MetaUpdate: func(meta *commands.Metadata) {
meta.ShortUsage = fmt.Sprintf("config set %s <value>", meta.Name)
MetaUpdate: func(meta *commands.Metadata, inputType string) {
meta.ShortUsage = fmt.Sprintf("config set %s <%s>", meta.Name, inputType)
},
TagNameSelector: "json",
TreeDisplay: true,
Expand Down
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/secrets_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func newSecretsGetCmd(io commands.IO) *commands.Command {

// Add subcommand helpers
helperGen := metadataHelperGenerator{
MetaUpdate: func(meta *commands.Metadata) {
meta.ShortUsage = "secrets get " + meta.Name
MetaUpdate: func(meta *commands.Metadata, inputType string) {
meta.ShortUsage = fmt.Sprintf("secrets get %s <%s>", meta.Name, inputType)
},
TagNameSelector: "json",
TreeDisplay: false,
Expand Down

0 comments on commit 25b3dc3

Please sign in to comment.