8000 feat(template): add `--no-simulation` flag by Pantani · Pull Request #1938 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(template): add --no-simulation flag #1938

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

Merged
merged 8 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions integration/list/cmd_list_test.go
10000
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestGenerateAnAppWithStargateWithListAndVerify(t *testing.T) {
"textCoin:coin",
"textCoins:array.coin",
"textCoinsAlias:coins",
"--no-simulation",
),
step.Workdir(path),
)),
Expand Down
11 changes: 10 additions & 1 deletion integration/map/cmd_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ func TestCreateMapWithStargate(t *testing.T) {

env.Must(env.Exec("create a list",
step.NewSteps(step.New(
step.Exec("starport", "s", "list", "user", "email", "--module", "example"),
step.Exec(
"starport",
"s",
"list",
"user",
"email",
"--module",
"example",
"--no-simulation",
),
step.Workdir(path),
)),
))
Expand Down
1 change: 1 addition & 0 deletions integration/other_components/cmd_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestGenerateAnAppWithMessage(t *testing.T) {
"foo,bar:int,foobar:bool",
"--path",
"blog",
"--no-simulation",
),
step.Workdir(filepath.Dir(path)),
)),
Expand Down
7 changes: 7 additions & 0 deletions integration/simulation/simapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func TestGenerateAnAppAndSimulate(t *testing.T) {
)),
))

env.Must(env.Exec("create an singleton type",
step.NewSteps(step.New(
step.Exec("starport", "s", "list", "noSimapp", "foobar", "--no-simulation"),
step.Workdir(path),
)),
))

env.Must(env.Exec("create a message",
step.NewSteps(step.New(
step.Exec("starport", "s", "msgFoo", "foobar"),
Expand Down
37 changes: 25 additions & 12 deletions starport/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

// flags related to component scaffolding
const (
flagModule = "module"
flagNoMessage = "no-message"
flagResponse = "response"
flagDescription = "desc"
flagModule = "module"
flagNoMessage = "no-message"
flagNoSimulation = "no-simulation"
flagResponse = "response"
flagDescription = "desc"
)

// NewScaffold returns a command that groups scaffolding related sub commands.
Expand Down Expand Up @@ -53,12 +54,13 @@ func scaffoldType(
kind scaffolder.AddTypeKind,
) error {
var (
typeName = args[0]
fields = args[1:]
moduleName = flagGetModule(cmd)
withoutMessage = flagGetNoMessage(cmd)
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
typeName = args[0]
fields = args[1:]
moduleName = flagGetModule(cmd)
withoutMessage = flagGetNoMessage(cmd)
withoutSimulation = flagGetNoSimulation(cmd)
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
)

var options []scaffolder.AddTypeOption
Expand All @@ -71,8 +73,13 @@ func scaffoldType(
}
if withoutMessage {
options = append(options, scaffolder.TypeWithoutMessage())
} else if signer != "" {
options = append(options, scaffolder.TypeWithSigner(signer))
} else {
if signer != "" {
options = append(options, scaffolder.TypeWithSigner(signer))
}
if withoutSimulation {
options = append(options, scaffolder.TypeWithoutSimulation())
}
}

s := clispinner.New().SetText("Scaffolding...")
Expand Down Expand Up @@ -105,6 +112,7 @@ func flagSetScaffoldType() *flag.FlagSet {
f := flag.NewFlagSet("", flag.ContinueOnError)
f.String(flagModule, "", "Module to add into. Default is app's main module")
f.Bool(flagNoMessage, false, "Disable CRUD interaction messages scaffolding")
f.Bool(flagNoSimulation, false, "Disable CRUD simulation scaffolding")
f.String(flagSigner, "", "Label for the message signer (default: creator)")
return f
}
Expand All @@ -114,6 +122,11 @@ func flagGetModule(cmd *cobra.Command) string {
return module
}

func flagGetNoSimulation(cmd *cobra.Command) bool {
noMessage, _ := cmd.Flags().GetBool(flagNoSimulation)
return noMessage
}

func flagGetNoMessage(cmd *cobra.Command) bool {
noMessage, _ := cmd.Flags().GetBool(flagNoMessage)
return noMessage
Expand Down
17 changes: 12 additions & 5 deletions starport/cmd/scaffold_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewScaffoldMessage() *cobra.Command {
flagSetPath(c)
c.Flags().String(flagModule, "", "Module to add the message into. Default: app's main module")
c.Flags().StringSliceP(flagResponse, "r", []string{}, "Response fields")
c.Flags().Bool(flagNoSimulation, false, "Disable CRUD simulation scaffolding")
c.Flags().StringP(flagDescription, "d", "", "Description of the command")
c.Flags().String(flagSigner, "", "Label for the message signer (default: creator)")

Expand All @@ -31,11 +32,12 @@ func NewScaffoldMessage() *cobra.Command {

func messageHandler(cmd *cobra.Command, args []string) error {
var (
module, _ = cmd.Flags().GetString(flagModule)
resFields, _ = cmd.Flags().GetStringSlice(flagResponse)
desc, _ = cmd.Flags().GetString(flagDescription)
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
module, _ = cmd.Flags().GetString(flagModule)
resFields, _ = cmd.Flags().GetStringSlice(flagResponse)
desc, _ = cmd.Flags().GetString(flagDescription)
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
withoutSimulation = flagGetNoSimulation(cmd)
)

s := clispinner.New().SetText("Scaffolding...")
Expand All @@ -53,6 +55,11 @@ func messageHandler(cmd *cobra.Command, args []string) error {
options = append(options, scaffolder.WithSigner(signer))
}

// Skip scaffold simulation
if withoutSimulation {
options = append(options, scaffolder.WithoutSimulation())
}

sc, err := newApp(appPath)
if err != nil {
return err
Expand Down
33 changes: 21 additions & 12 deletions starport/services/scaffolder/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (

// messageOptions represents configuration for the message scaffolding
type messageOptions struct {
description string
signer string
description string
signer string
withoutSimulation bool
}

// newMessageOptions returns a messageOptions with default options
Expand Down Expand Up @@ -45,6 +46,13 @@ func WithSigner(signer string) MessageOption {
}
}

// WithoutSimulation disables generating messages simulation
func WithoutSimulation() MessageOption {
return func(m *messageOptions) {
m.withoutSimulation = true
}
}

// AddMessage adds a new message to scaffolded app
func (s Scaffolder) AddMessage(
ctx context.Context,
Expand Down Expand Up @@ -106,16 +114,17 @@ func (s Scaffolder) AddMessage(
var (
g *genny.Generator
opts = &message.Options{
AppName: s.modpath.Package,
AppPath: s.path,
ModulePath: s.modpath.RawPath,
ModuleName: moduleName,
OwnerName: owner(s.modpath.RawPath),
MsgName: name,
Fields: parsedMsgFields,
ResFields: parsedResFields,
MsgDesc: scaffoldingOpts.description,
MsgSigner: mfSigner,
AppName: s.modpath.Package,
AppPath: s.path,
ModulePath: s.modpath.RawPath,
ModuleName: moduleName,
OwnerName: owner(s.modpath.RawPath),
MsgName: name,
Fields: parsedMsgFields,
ResFields: parsedResFields,
MsgDesc: scaffoldingOpts.description,
MsgSigner: mfSigner,
NoSimulation: scaffoldingOpts.withoutSimulation,
}
)

Expand Down
33 changes: 21 additions & 12 deletions starport/services/scaffolder/type.go
Original file line number Diff line number Diff line change
< 10000 a href="#diff-e31e73ae0776f4971ed7716aa0b949e2b5b3b335d21d8996b85439edf0cb8903" id="expand-up-link-0-diff-e31e73ae0776f4971ed7716aa0b949e2b5b3b335d21d8996b85439edf0cb8903" class="js-expand directional-expander single-expander" aria-label="Expand Up" data-url="/ignite/cli/blob_excerpt/7ccae0a3428c82819d226e4e83ce2baaa1d448f4?context=pull_request&diff=unified&direction=up&in_wiki_context&last_left&last_right&left=35&left_hunk_size=8&mode=100644&path=starport%2Fservices%2Fscaffolder%2Ftype.go&pull_request_id=804916145&right=35&right_hunk_size=9" data-left-range="1-34" data-right-range="1-34"> Expand Up @@ -35,8 +35,9 @@ type addTypeOptions struct {

indexes []string

withoutMessage bool
signer string
withoutMessage bool
withoutSimulation bool
signer string
}

// newAddTypeOptions returns a addTypeOptions with default options
Expand Down Expand Up @@ -96,6 +97,13 @@ func TypeWithoutMessage() AddTypeOption {
}
}

// TypeWithoutSimulation disables generating messages simulation.
func TypeWithoutSimulation() AddTypeOption {
return func(o *addTypeOptions) {
o.withoutSimulation = true
}
}

// TypeWithSigner provides a custom signer name for the message
func TypeWithSigner(signer string) AddTypeOption {
return func(o *addTypeOptions) {
Expand Down Expand Up @@ -162,16 +170,17 @@ func (s Scaffolder) AddType(
var (
g *genny.Generator
opts = &typed.Options{
AppName: s.modpath.Package,
AppPath: s.path,
ModulePath: s.modpath.RawPath,
ModuleName: moduleName,
OwnerName: owner(s.modpath.RawPath),
TypeName: name,
Fields: tFields,
NoMessage: o.withoutMessage,
MsgSigner: mfSigner,
IsIBC: isIBC,
AppName: s.modpath.Package,
AppPath: s.path,
ModulePath: s.modpath.RawPath,
ModuleName: moduleName,
OwnerName: owner(s.modpath.RawPath),
TypeName: name,
Fields: tFields,
NoMessage: o.withoutMessage,
NoSimulation: o.withoutSimulation,
MsgSigner: mfSigner,
IsIBC: isIBC,
}
gens []*genny.Generator
)
Expand Down
7 changes: 5 additions & 2 deletions starport/templates/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
)

var (
//go:embed stargate/* stargate/**/*
fsStargate embed.FS
//go:embed stargate/message/* stargate/message/**/*
fsStargateMessage embed.FS

//go:embed stargate/simapp/* stargate/simapp/**/*
fsStargateSimapp embed.FS
)

func Box(box packd.Walker, opts *Options, g *genny.Generator) error {
Expand Down
21 changes: 11 additions & 10 deletions starport/templates/message/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import (

// Options ...
type Options struct {
AppName string
AppPath string
ModuleName string
ModulePath string
OwnerName string
MsgName multiformatname.Name
MsgSigner multiformatname.Name
MsgDesc string
Fields field.Fields
ResFields field.Fields
AppName string
AppPath string
ModuleName string
ModulePath string
OwnerName string
MsgName multiformatname.Name
MsgSigner multiformatname.Name
MsgDesc string
Fields field.Fields
ResFields field.Fields
NoSimulation bool
}

// Validate that options are usuable
Expand Down
17 changes: 14 additions & 3 deletions starport/templates/message/stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ func NewStargate(replacer placeholder.Replacer, opts *Options) (*genny.Generator
g.RunFn(protoTxMessageModify(replacer, opts))
g.RunFn(typesCodecModify(replacer, opts))
g.RunFn(clientCliTxModify(replacer, opts))
g.RunFn(moduleSimulationModify(replacer, opts))

template := xgenny.NewEmbedWalker(
fsStargate,
"stargate/",
fsStargateMessage,
"stargate/message",
opts.AppPath,
)

if !opts.NoSimulation {
g.RunFn(moduleSimulationModify(replacer, opts))
simappTemplate := xgenny.NewEmbedWalker(
fsStargateSimapp,
"stargate/simapp",
opts.AppPath,
)
if err := Box(simappTemplate, opts, g); err != nil {
return nil, err
}
}
return g, Box(template, opts, g)
}

Expand Down
16 changes: 15 additions & 1 deletion starport/templates/typed/list/stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var (

//go:embed stargate/messages/* stargate/messages/**/*
fsStargateMessages embed.FS

//go:embed stargate/simapp/* stargate/simapp/**/*
fsStargateSimapp embed.FS
)

// NewStargate returns the generator to scaffold a new type in a Stargate module
Expand All @@ -36,6 +39,11 @@ func NewStargate(replacer placeholder.Replacer, opts *typed.Options) (*genny.Gen
"stargate/component/",
opts.AppPath,
)
simappTemplate = xgenny.NewEmbedWalker(
fsStargateSimapp,
"stargate/simapp/",
opts.AppPath,
)
)

g.RunFn(protoQueryModify(replacer, opts))
Expand All @@ -52,7 +60,13 @@ func NewStargate(replacer placeholder.Replacer, opts *typed.Options) (*genny.Gen
g.RunFn(protoTxModify(replacer, opts))
g.RunFn(typesCodecModify(replacer, opts))
g.RunFn(clientCliTxModify(replacer, opts))
g.RunFn(moduleSimulationModify(replacer, opts))

if !opts.NoSimulation {
g.RunFn(moduleSimulationModify(replacer, opts))
if err := typed.Box(simappTemplate, opts, g); err != nil {
return nil, err
}
}

// Messages template
if err := typed.Box(messagesTemplate, opts, g); err != nil {
Expand Down
Loading
0