-
Notifications
You must be signed in to change notification settings - Fork 532
/
scaffold_params.go
94 lines (72 loc) · 2.3 KB
/
scaffold_params.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package ignitecmd
import (
"strings"
"github.com/spf13/cobra"
"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)
// NewScaffoldParams returns the command to scaffold a Cosmos SDK parameters into a module.
func NewScaffoldParams() *cobra.Command {
c := &cobra.Command{
Use: "params [param]...",
Short: "Parameters for a custom Cosmos SDK module",
Long: `Scaffold a new parameter for a Cosmos SDK module.
A Cosmos SDK module can have parameters (or "params"). Params are values that
can be set at the genesis of the blockchain and can be modified while the
blockchain is running. An example of a param is "Inflation rate change" of the
"mint" module. A params can be scaffolded into a module using the "--params" into
the scaffold module command or using the "scaffold params" command. By default
params are of type "string", but you can specify a type for each param. For example:
ignite scaffold params foo baz:uint bar:bool
Refer to Cosmos SDK documentation to learn more about modules, dependencies and
params.
`,
Args: cobra.MinimumNArgs(1),
PreRunE: migrationPreRunHandler,
RunE: scaffoldParamsHandler,
}
flagSetPath(c)
flagSetClearCache(c)
c.Flags().AddFlagSet(flagSetYes())
c.Flags().String(flagModule, "", "module to add the query into. Default: app's main module")
return c
}
func scaffoldParamsHandler(cmd *cobra.Command, args []string) error {
var (
params = args[0:]
appPath = flagGetPath(cmd)
moduleName = flagGetModule(cmd)
)
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
defer session.End()
cfg, _, err := getChainConfig(cmd)
if err != nil {
return err
}
cacheStorage, err := newCache(cmd)
if err != nil {
return err
}
sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path)
if err != nil {
return err
}
err = sc.CreateParams(moduleName, params...)
if err != nil {
return err
}
sm, err := sc.ApplyModifications()
if err != nil {
return err
}
if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}
modificationsStr, err := sm.String()
if err != nil {
return err
}
session.Println(modificationsStr)
session.Printf("\n🎉 New parameters added to the module:\n\n- %s\n\n", strings.Join(params, "\n- "))
return nil
}