@@ -12,9 +12,38 @@ import (
1212 "github.com/ignite/cli/v29/ignite/pkg/errors"
1313)
1414
15+ type addModuleAppConfigOptions struct {
16+ skipConfig bool
17+ runtimeFields []string
18+ }
19+
20+ type AddModuleAppConfigOption func (* addModuleAppConfigOptions )
21+
22+ func SkipConfigEntry () AddModuleAppConfigOption {
23+ return func (opts * addModuleAppConfigOptions ) {
24+ opts .skipConfig = true
25+ }
26+ }
27+
28+ // SpecifyModuleEntry allows to define to which field the module should be added in the app config.
29+ // E.g. "PreBlockers", "InitGenesis", "BeginBlockers", "EndBlockers"
30+ func SpecifyModuleEntry (fields ... string ) AddModuleAppConfigOption {
31+ return func (opts * addModuleAppConfigOptions ) {
32+ opts .runtimeFields = fields
33+ }
34+ }
35+
1536// AddModuleToAppConfig appends a given module to the chain app config.
16- // TODO: Eventually add variadic options to specify adding before or after a module.
17- func AddModuleToAppConfig (content , moduleName string ) (string , error ) {
37+ func AddModuleToAppConfig (content , moduleName string , opts ... AddModuleAppConfigOption ) (string , error ) {
38+ options := addModuleAppConfigOptions {}
39+ for _ , opt := range opts {
40+ opt (& options )
41+ }
42+ return AddModuleToAppConfigWithOptions (content , moduleName , options )
43+ }
44+
45+ // AddModuleToAppConfigWithOptions appends a given module to the chain app config with options.
46+ func AddModuleToAppConfigWithOptions (content , moduleName string , opts addModuleAppConfigOptions ) (string , error ) {
1847 fileSet := token .NewFileSet ()
1948 file , err := parser .ParseFile (fileSet , "" , content , parser .ParseComments )
2049 if err != nil {
@@ -37,14 +66,21 @@ func AddModuleToAppConfig(content, moduleName string) (string, error) {
3766 return "" , err
3867 }
3968
40- for _ , fieldName := range []string {"InitGenesis" , "BeginBlockers" , "EndBlockers" } {
69+ fields := opts .runtimeFields
70+ if len (fields ) == 0 {
71+ fields = []string {"InitGenesis" , "BeginBlockers" , "EndBlockers" }
72+ }
73+
74+ for _ , fieldName := range fields {
4175 if err := appendModuleNameToRuntimeField (file , runtimeModuleLit , fieldName , moduleName , fileSet ); err != nil {
4276 return "" , err
4377 }
4478 }
4579
46- if err := appendModuleConfigEntry (file , modulesField .Value , moduleName , fileSet ); err != nil {
47- return "" , err
80+ if ! opts .skipConfig {
81+ if err := appendModuleConfigEntry (file , modulesField .Value , moduleName , fileSet ); err != nil {
82+ return "" , err
83+ }
4884 }
4985
5086 file .Comments = commentMap .Filter (file ).Comments ()
0 commit comments