Skip to content
7 changes: 7 additions & 0 deletions integration/cmd_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func TestGenerateAnAppWithStargateWithTypeAndVerify(t *testing.T) {
ExecShouldError(),
))

env.Must(env.Exec("create a type with no interaction message",
step.NewSteps(step.New(
step.Exec("starport", "type", "nomessage", "email", "--no-message"),
step.Workdir(path),
)),
))

env.EnsureAppIsSteady(path)
}

Expand Down
12 changes: 9 additions & 3 deletions starport/cmd/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

const (
flagModule string = "module"
flagLegacy string = "legacy"
flagIndexed string = "indexed"
flagModule string = "module"
flagLegacy string = "legacy"
flagIndexed string = "indexed"
flagNoMessage string = "no-message"
)

// NewType command creates a new type command to scaffold types.
Expand All @@ -28,6 +29,7 @@ func NewType() *cobra.Command {
c.Flags().String(flagModule, "", "Module to add the type into. Default: app's main module")
c.Flags().Bool(flagLegacy, false, "Scaffold the type without generating MsgServer service")
c.Flags().Bool(flagIndexed, false, "Scaffold an indexed type")
c.Flags().Bool(flagNoMessage, false, "Disable CRUD interaction messages scaffolding")

return c
}
Expand All @@ -52,6 +54,10 @@ func typeHandler(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
opts.NoMessage, err = cmd.Flags().GetBool(flagNoMessage)
if err != nil {
return err
}

sc := scaffolder.New(appPath)
if err := sc.AddType(opts, module, args[0], args[1:]...); err != nil {
Expand Down
12 changes: 10 additions & 2 deletions starport/services/scaffolder/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const (
)

type AddTypeOption struct {
Legacy bool
Indexed bool
Legacy bool
Indexed bool
NoMessage bool
}

// AddType adds a new type stype to scaffolded app by using optional type fields.
Expand Down Expand Up @@ -84,6 +85,7 @@ func (s *Scaffolder) AddType(addTypeOptions AddTypeOption, moduleName string, ty
TypeName: typeName,
Fields: tFields,
Legacy: addTypeOptions.Legacy,
NoMessage: addTypeOptions.NoMessage,
}
)
// generate depending on the version
Expand All @@ -109,6 +111,12 @@ func (s *Scaffolder) AddType(addTypeOptions AddTypeOption, moduleName string, ty
if !msgServerDefined {
opts.Legacy = true
}

// Can't use no message option for legacy types
if opts.Legacy && opts.NoMessage {
return errors.New("legacy types cannot by scaffolded with no message option")
}

g, err = typed.NewStargate(opts)
}
}
Expand Down
1 change: 1 addition & 0 deletions starport/templates/typed/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Options struct {
TypeName string
Fields []Field
Legacy bool
NoMessage bool
}

// Validate that options are usuable
Expand Down
Loading