Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set positional args for delete commands and scaffolded autocli config #3822

Merged
merged 9 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changes

- [#3822](https://github.com/ignite/cli/pull/3822) Improve default scaffolded AutoCLI config

## [`v28.0.0`](https://github.com/ignite/cli/releases/tag/v28.0.0)

### Features
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
Loading