Skip to content

Commit 64c2d0b

Browse files
authored
feat: add all types to the documentation and disclaimer for multiple coin types (#4786)
1 parent c3b7fd2 commit 64c2d0b

File tree

14 files changed

+295
-79
lines changed

14 files changed

+295
-79
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- [#4786](https://github.com/ignite/cli/pull/4786) Add all types to the documentation and disclaimer for multiple coin types.
8+
59
## [`v29.2.1`](https://github.com/ignite/cli/releases/tag/v29.2.1)
610

711
### Changes

ignite/cmd/scaffold.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
flag "github.com/spf13/pflag"
66

77
"github.com/ignite/cli/v29/ignite/pkg/cliui"
8+
"github.com/ignite/cli/v29/ignite/pkg/cliui/colors"
89
"github.com/ignite/cli/v29/ignite/pkg/cosmosver"
910
"github.com/ignite/cli/v29/ignite/pkg/env"
1011
"github.com/ignite/cli/v29/ignite/pkg/errors"
1112
"github.com/ignite/cli/v29/ignite/pkg/gocmd"
1213
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
1314
"github.com/ignite/cli/v29/ignite/pkg/xgit"
1415
"github.com/ignite/cli/v29/ignite/services/scaffolder"
16+
"github.com/ignite/cli/v29/ignite/templates/field"
1517
"github.com/ignite/cli/v29/ignite/version"
1618
)
1719

@@ -27,28 +29,12 @@ const (
2729
msgCommitPrefix = "Your project changes have not been committed.\nTo enable reverting to your current state, commit your saved changes."
2830
msgCommitPrompt = "Do you want to proceed without committing your saved changes"
2931

30-
statusScaffolding = "Scaffolding..."
31-
32-
supportFieldTypes = `
33-
Currently supports:
34-
35-
| Type | Alias | Index | Code Type | Description |
36-
|--------------|---------|-------|-----------|---------------------------------|
37-
| string | - | yes | string | Text type |
38-
| array.string | strings | no | []string | List of text type |
39-
| bool | - | yes | bool | Boolean type |
40-
| int | - | yes | int64 | Integer type |
41-
| array.int | ints | no | []int64 | List of integers types |
42-
| uint | - | yes | uint64 | Unsigned integer type |
43-
| array.uint | uints | no | []uint64 | List of unsigned integers types |
44-
| coin | - | no | sdk.Coin | Cosmos SDK coin type |
45-
| array.coin | coins | no | sdk.Coins | List of Cosmos SDK coin types |
46-
47-
Field Usage:
48-
- fieldName
49-
- fieldName:fieldType
50-
51-
If no :fieldType, default (string) is used
32+
statusScaffolding = "Scaffolding..."
33+
multipleCoinDisclaimer = `**Disclaimer**
34+
The 'coins' and 'dec.coins' argument types require special attention when used in CLI commands.
35+
Due to current limitations in the AutoCLI, only one variadic (slice) argument is supported per command.
36+
If a message contains more than one field of type 'coins' or 'dec.coins', only the last one will accept multiple values via the CLI.
37+
For the best user experience, manual command handling or scaffolding is recommended when working with messages containing multiple 'coins' or 'dec.coins' fields.
5238
`
5339
)
5440

@@ -220,6 +206,18 @@ func scaffoldType(
220206
)
221207
defer session.End()
222208

209+
if !withoutMessage {
210+
hasMultipleCoinSlice, err := field.MultipleCoins(fields)
211+
if err != nil {
212+
return err
213+
}
214+
if hasMultipleCoinSlice {
215+
session.PauseSpinner()
216+
_ = session.Print(colors.Info(multipleCoinDisclaimer))
217+
session.StartSpinner(statusScaffolding)
218+
}
219+
}
220+
223221
cfg, _, err := getChainConfig(cmd)
224222
if err != nil {
225223
return err

ignite/cmd/scaffold_message.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"github.com/spf13/cobra"
55

66
"github.com/ignite/cli/v29/ignite/pkg/cliui"
7+
"github.com/ignite/cli/v29/ignite/pkg/cliui/colors"
78
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
89
"github.com/ignite/cli/v29/ignite/services/scaffolder"
10+
"github.com/ignite/cli/v29/ignite/templates/field"
911
)
1012

1113
const flagSigner = "signer"
@@ -95,6 +97,16 @@ func messageHandler(cmd *cobra.Command, args []string) error {
9597
)
9698
defer session.End()
9799

100+
hasMultipleCoinSlice, err := field.MultipleCoins(resFields)
101+
if err != nil {
102+
return err
103+
}
104+
if hasMultipleCoinSlice {
105+
session.PauseSpinner()
106+
_ = session.Print(colors.Info(multipleCoinDisclaimer))
107+
session.StartSpinner(statusScaffolding)
108+
}
109+
98110
cfg, _, err := getChainConfig(cmd)
99111
if err != nil {
100112
return err

ignite/cmd/scaffold_type.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ package ignitecmd
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/spf13/cobra"
78

89
"github.com/ignite/cli/v29/ignite/services/scaffolder"
10+
"github.com/ignite/cli/v29/ignite/templates/field/datatype"
911
)
1012

1113
// NewScaffoldType returns a new command to scaffold a type.
1214
func NewScaffoldType() *cobra.Command {
15+
b := strings.Builder{}
16+
_ = datatype.PrintScaffoldTypeList(&b)
17+
1318
c := &cobra.Command{
1419
Use: "type NAME [field:type] ...",
1520
Short: "Type definition",
16-
Long: fmt.Sprintf("Type information\n%s\n", supportFieldTypes),
21+
Long: fmt.Sprintf("Type information\n\n%s\n", b.String()),
1722
Example: " ignite scaffold type todo-item priority:int desc:string tags:array.string done:bool",
1823
Args: cobra.MinimumNArgs(1),
1924
PreRunE: migrationPreRunHandler,

ignite/cmd/scaffold_type_list.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package ignitecmd
22

33
import (
4-
"sort"
5-
64
"github.com/spf13/cobra"
75

86
"github.com/ignite/cli/v29/ignite/pkg/cliui"
@@ -16,28 +14,16 @@ func NewScaffoldTypeList() *cobra.Command {
1614
Short: "List scaffold types",
1715
Long: "List all available scaffold types",
1816
Args: cobra.NoArgs,
19-
RunE: scaffoldTypeListHandler,
17+
RunE: func(cmd *cobra.Command, _ []string) error {
18+
session := cliui.New(
19+
cliui.StartSpinnerWithText("printing..."),
20+
cliui.WithoutUserInteraction(getYes(cmd)),
21+
)
22+
defer session.End()
23+
session.StopSpinner()
24+
return datatype.PrintScaffoldTypeList(cmd.OutOrStdout())
25+
},
2026
}
2127

2228
return c
2329
}
24-
25-
func scaffoldTypeListHandler(cmd *cobra.Command, _ []string) error {
26-
session := cliui.New(
27-
cliui.StartSpinnerWithText("printing..."),
28-
cliui.WithoutUserInteraction(getYes(cmd)),
29-
)
30-
defer session.End()
31-
32-
supported := datatype.SupportedTypes()
33-
entries := make([][]string, 0, len(supported))
34-
for name, usage := range supported {
35-
entries = append(entries, []string{name, usage})
36-
}
37-
38-
sort.Slice(entries, func(i, j int) bool {
39-
return entries[i][0] < entries[j][0]
40-
})
41-
42-
return session.PrintTable([]string{"types", "usage"}, entries...)
43-
}

ignite/internal/tools/gen-cli-docs/main.go

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log"
1212
"os"
1313
"path/filepath"
14+
"sort"
1415
"strings"
1516

1617
"github.com/spf13/cobra"
@@ -20,9 +21,28 @@ import (
2021
pluginsconfig "github.com/ignite/cli/v29/ignite/config/plugins"
2122
"github.com/ignite/cli/v29/ignite/pkg/env"
2223
"github.com/ignite/cli/v29/ignite/services/plugin"
24+
"github.com/ignite/cli/v29/ignite/templates/field/datatype"
2325
)
2426

2527
const (
28+
scaffoldTypeFooter = `
29+
30+
Field Usage:
31+
32+
- fieldName
33+
- fieldName:fieldType
34+
35+
36+
If no :fieldType, default (string) is used
37+
`
38+
scaffoldTypeHead = `# Scaffold Type
39+
40+
Ignites provides a set of scaffold types that can be used to generate code for your application.
41+
These types are used in the ` + "`ignite scaffold`" + ` command.
42+
43+
## Available Scaffold Types
44+
45+
`
2646
head = `---
2747
description: Ignite CLI docs.
2848
---
@@ -67,7 +87,8 @@ func run() error {
6787
return err
6888
}
6989
defer cleanUp()
70-
cmd.Flags().String(outFlag, ".", ".md file path to place Ignite CLI docs inside")
90+
91+
cmd.Flags().String(outFlag, "output.md", ".md file path to place Ignite CLI docs inside")
7192
if err := cmd.Flags().MarkHidden(outFlag); err != nil {
7293
return err
7394
}
@@ -83,10 +104,10 @@ func run() error {
83104
return nil
84105
}
85106

86-
return generate(cmd, outPath)
107+
return generateUsage(cmd, outPath)
87108
}
88109

89-
func generate(cmd *cobra.Command, outPath string) error {
110+
func generateUsage(cmd *cobra.Command, outPath string) error {
90111
if err := os.MkdirAll(filepath.Dir(outPath), 0o755); err != nil {
91112
return err
92113
}
@@ -100,7 +121,47 @@ func generate(cmd *cobra.Command, outPath string) error {
100121
return err
101122
}
102123

103-
return generateCmd(cmd, f)
124+
if err := generateCmd(cmd, f); err != nil {
125+
return err
126+
}
127+
128+
return generateScaffoldTypes(f)
129+
}
130+
131+
func generateScaffoldTypes(w io.Writer) error {
132+
if _, err := fmt.Fprint(w, scaffoldTypeHead); err != nil {
133+
return err
134+
}
135+
136+
supported := datatype.SupportedTypes()
137+
entries := make([][]string, 0, len(supported))
138+
for name, usage := range supported {
139+
entries = append(entries, []string{name, usage})
140+
}
141+
142+
sort.Slice(entries, func(i, j int) bool {
143+
return entries[i][0] < entries[j][0]
144+
})
145+
146+
// Write table header
147+
if _, err := fmt.Fprintf(w, "| Type | Usage |\n"); err != nil {
148+
return err
149+
}
150+
if _, err := fmt.Fprintf(w, "| --- | --- |\n"); err != nil {
151+
return err
152+
}
153+
154+
// Write table rows
155+
for _, entry := range entries {
156+
if _, err := fmt.Fprintf(w, "| %s | %s |\n", entry[0], entry[1]); err != nil {
157+
return err
158+
}
159+
}
160+
161+
if _, err := fmt.Fprint(w, scaffoldTypeFooter); err != nil {
162+
return err
163+
}
164+
return nil
104165
}
105166

106167
func generateCmd(cmd *cobra.Command, w io.Writer) error {

ignite/pkg/multiformatname/multiformatname.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ type Name struct {
2323

2424
type Checker func(name string) error
2525

26+
// MustNewName returns a new multi-format name from a name.
27+
func MustNewName(name string, additionalChecks ...Checker) Name {
28+
n, err := NewName(name, additionalChecks...)
29+
if err != nil {
30+
panic(err)
31+
}
32+
return n
33+
}
34+
2635
// NewName returns a new multi-format name from a name.
2736
func NewName(name string, additionalChecks ...Checker) (Name, error) {
2837
checks := append([]Checker{basicCheckName}, additionalChecks...)

ignite/templates/field/datatype/coin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070

7171
// DataDecCoin decimal coin data type definition.
7272
DataDecCoin = DataType{
73+
Name: DecCoin,
7374
DataType: func(string) string { return "sdk.DecCoin" },
7475
CollectionsKeyValueName: func(string) string { return collectionValueComment },
7576
DefaultTestValue: "100001token",
@@ -98,6 +99,7 @@ var (
9899

99100
// DataDecCoinSlice is a decimal coin array data type definition.
100101
DataDecCoinSlice = DataType{
102+
Name: DecCoins,
101103
DataType: func(string) string { return "sdk.DecCoins" },
102104
CollectionsKeyValueName: func(string) string { return collectionValueComment },
103105
DefaultTestValue: "20000002stake",

0 commit comments

Comments
 (0)