Skip to content

Commit

Permalink
feat: set positional args for delete commands and scaffolded autocli …
Browse files Browse the repository at this point in the history
…config (#3822)
  • Loading branch information
julienrbrt authored Dec 12, 2023
1 parent a40ccc8 commit c8c9f8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changes

- [#3822](https://github.com/ignite/cli/pull/3822) Improve default scaffolded AutoCLI config
- [#3838](https://github.com/ignite/cli/pull/3838) Scaffold chain with Cosmos SDK `v0.50.2`, and bump confix and x/upgrade to latest

### Fixes
Expand Down
13 changes: 8 additions & 5 deletions ignite/templates/typed/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,27 +336,29 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *typed.Options) genny
return err
}

var positionalArgs string
var positionalArgs, positionalArgsStr string
for _, field := range opts.Fields {
positionalArgs += fmt.Sprintf(`{ProtoField: "%s"}, `, field.ProtoFieldName())
positionalArgsStr += fmt.Sprintf("[%s] ", field.ProtoFieldName())
}

template := `{
RpcMethod: "Create%[2]v",
Use: "create-%[3]v",
Use: "create-%[3]v %[6]s",
Short: "Create %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
},
{
RpcMethod: "Update%[2]v",
Use: "update-%[3]v",
Use: "update-%[3]v [id] %[6]s",
Short: "Update %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "id"}, %[5]s},
},
{
RpcMethod: "Delete%[2]v",
Use: "delete-%[3]v",
Use: "delete-%[3]v [id]",
Short: "Delete %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "id"}},
},
%[1]v`

Expand All @@ -367,6 +369,7 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *typed.Options) genny
opts.TypeName.Kebab,
opts.TypeName.Original,
strings.TrimSpace(positionalArgs),
strings.TrimSpace(positionalArgsStr),
)

content := replacer.Replace(f.String(), typed.PlaceholderAutoCLITx, replacement)
Expand Down
19 changes: 14 additions & 5 deletions ignite/templates/typed/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,30 +627,36 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *typed.Options) genny
return err
}

var positionalArgs string
var positionalArgs, positionalArgsStr string
var indexes, indexesStr string
for _, field := range opts.Fields {
positionalArgs += fmt.Sprintf(`{ProtoField: "%s"}, `, field.ProtoFieldName())
positionalArgsStr += fmt.Sprintf("[%s] ", field.ProtoFieldName())
}
for _, field := range opts.Indexes {
positionalArgs += fmt.Sprintf(`{ProtoField: "%s"}, `, field.ProtoFieldName())
indexes += fmt.Sprintf(`{ProtoField: "%s"}, `, field.ProtoFieldName())
indexesStr += fmt.Sprintf("[%s] ", field.ProtoFieldName())
}
positionalArgs = indexes + positionalArgs
positionalArgsStr = indexesStr + positionalArgsStr

template := `{
RpcMethod: "Create%[2]v",
Use: "create-%[3]v",
Use: "create-%[3]v %[6]s",
Short: "Create a new %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
},
{
RpcMethod: "Update%[2]v",
Use: "update-%[3]v",
Use: "update-%[3]v %[6]s",
Short: "Update %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
},
{
RpcMethod: "Delete%[2]v",
Use: "delete-%[3]v",
Use: "delete-%[3]v %[8]s",
Short: "Delete %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[7]s},
},
%[1]v`

Expand All @@ -661,6 +667,9 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *typed.Options) genny
opts.TypeName.Kebab,
opts.TypeName.Original,
strings.TrimSpace(positionalArgs),
strings.TrimSpace(positionalArgsStr),
strings.TrimSpace(indexes),
strings.TrimSpace(indexesStr),
)

content := replacer.Replace(f.String(), typed.PlaceholderAutoCLITx, replacement)
Expand Down
8 changes: 5 additions & 3 deletions ignite/templates/typed/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,21 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *typed.Options) genny
return err
}

var positionalArgs string
var positionalArgs, positionalArgsStr string
for _, field := range opts.Fields {
positionalArgs += fmt.Sprintf(`{ProtoField: "%s"}, `, field.ProtoFieldName())
positionalArgsStr += fmt.Sprintf("[%s] ", field.ProtoFieldName())
}

template := `{
RpcMethod: "Create%[2]v",
Use: "create-%[3]v",
Use: "create-%[3]v %[6]s",
Short: "Create %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
},
{
RpcMethod: "Update%[2]v",
Use: "update-%[3]v",
Use: "update-%[3]v %[6]s",
Short: "Update %[4]v",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
},
Expand All @@ -491,6 +492,7 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *typed.Options) genny
opts.TypeName.Kebab,
opts.TypeName.Original,
strings.TrimSpace(positionalArgs),
strings.TrimSpace(positionalArgsStr),
)

content := replacer.Replace(f.String(), typed.PlaceholderAutoCLITx, replacement)
Expand Down

0 comments on commit c8c9f8e

Please sign in to comment.