-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
scaffold configs
and scaffold params
commands and start…
… remove placeholders (#3770) * add parameters placeholders and modifier * add scaffold params command * add changelog * check if the parameter already exist * add integration tests and fix some import issues * improve the scaffolder logic * improve the log message * fix the log message * fix changelog * fix 28 imports * remove params module * add module configs command * rollbak empty line for proto * improve code readbility and add unit tests * fix changelog * use cli error package * Update ignite/cmd/scaffold_configs.go Co-authored-by: Jerónimo Albi <[email protected]> * apply pr suggestions * fix some typos * remove unused vars and casting * add replacer pkg for goanalysis * add TODO comment * add modify call function * test readbility * improve organization * fix the function modifier logic * fix the arg idente for caller replace * add more test cases and last fixes * start replace the params template to the xast * add append struct param option * add support to add new struct params * fix some lint issues * add small fixes and improve code readbility * fix append code parser * fix changelog --------- Co-authored-by: Pantani <Pantani> Co-authored-by: Jerónimo Albi <[email protected]>
- Loading branch information
1 parent
002c99d
commit 1a276fd
Showing
33 changed files
with
2,614 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/cliui" | ||
"github.com/ignite/cli/v28/ignite/pkg/placeholder" | ||
"github.com/ignite/cli/v28/ignite/services/scaffolder" | ||
) | ||
|
||
// NewScaffoldConfigs returns the command to scaffold a Cosmos SDK configs into a module. | ||
func NewScaffoldConfigs() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "configs [configs]...", | ||
Short: "Configs for a custom Cosmos SDK module", | ||
Long: `Scaffold a new config for a Cosmos SDK module. | ||
A Cosmos SDK module can have configurations. An example of a config is "address prefix" of the | ||
"auth" module. A config can be scaffolded into a module using the "--module-configs" into | ||
the scaffold module command or using the "scaffold configs" command. By default | ||
configs are of type "string", but you can specify a type for each config. For example: | ||
ignite scaffold configs foo baz:uint bar:bool | ||
Refer to Cosmos SDK documentation to learn more about modules, dependencies and | ||
configs. | ||
`, | ||
Args: cobra.MinimumNArgs(1), | ||
PreRunE: migrationPreRunHandler, | ||
RunE: scaffoldConfigsHandler, | ||
} | ||
|
||
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 scaffoldConfigsHandler(cmd *cobra.Command, args []string) error { | ||
var ( | ||
configs = args[0:] | ||
appPath = flagGetPath(cmd) | ||
moduleName = flagGetModule(cmd) | ||
) | ||
|
||
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) | ||
defer session.End() | ||
|
||
cacheStorage, err := newCache(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sc, err := scaffolder.New(appPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sm, err := sc.CreateConfigs(cmd.Context(), cacheStorage, placeholder.New(), moduleName, configs...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
modificationsStr, err := sourceModificationToString(sm) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
session.Println(modificationsStr) | ||
session.Printf("\n🎉 New configs added to the module:\n\n- %s\n\n", strings.Join(configs, "\n- ")) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/cliui" | ||
"github.com/ignite/cli/v28/ignite/pkg/placeholder" | ||
"github.com/ignite/cli/v28/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() | ||
|
||
cacheStorage, err := newCache(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sc, err := scaffolder.New(appPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sm, err := sc.CreateParams(cmd.Context(), cacheStorage, placeholder.New(), moduleName, params...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
modificationsStr, err := sourceModificationToString(sm) | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.