Back to godoc.org
github.com/gobuffalo/buffalo/buffalo/cmd/generate

package generate

v0.16.9
Latest Go to latest
Published: May 25, 2020 | License: MIT | Module: github.com/gobuffalo/buffalo

Index

Variables

var ActionCmd = &cobra.Command{
	Use:     "action [name] [handler name...]",
	Aliases: []string{"a", "actions"},
	Short:   "Generate new action(s)",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return fmt.Errorf("you must provide a name")
		}
		actionOptions.Name = args[0]
		if len(args) == 1 {
			return fmt.Errorf("you must provide at least one action name")
		}
		actionOptions.Actions = args[1:]

		ctx := context.Background()
		run := genny.WetRunner(ctx)

		if actionOptions.dryRun {
			run = genny.DryRunner(ctx)
		}

		if actionOptions.verbose {
			run.Logger = logger.New(logger.DebugLevel)
		}

		opts := actionOptions.Options
		run.WithNew(actions.New(opts))
		return run.Run()
	},
}

ActionCmd is the cmd that generates actions.

var MailCmd = &cobra.Command{
	Use:   "mailer [name]",
	Short: "Generate a new mailer for Buffalo",
	RunE: func(cmd *cobra.Command, args []string) error {
		mailOptions.App = meta.New(".")
		mailOptions.Name = name.New(args[0])
		gg, err := mail.New(mailOptions.Options)
		if err != nil {
			return err
		}

		run := genny.WetRunner(context.Background())
		if mailOptions.dryRun {
			run = genny.DryRunner(context.Background())
		}

		g, err := gogen.Fmt(mailOptions.App.Root)
		if err != nil {
			return err
		}
		run.With(g)

		gg.With(run)
		return run.Run()

	},
}

MailCmd for generating mailers

var ResourceCmd = &cobra.Command{
	Use:     "resource [name]",
	Example: resourceExamples,
	Aliases: []string{"r"},
	Short:   "Generate a new actions/resource file",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return fmt.Errorf("you must supply a name")
		}
		ctx := context.Background()
		run := genny.WetRunner(ctx)
		if resourceOptions.DryRun {
			run = genny.DryRunner(ctx)
		}

		if resourceOptions.Verbose {
			lg := logger.New(logger.DebugLevel)
			run.Logger = lg
		}

		if len(resourceOptions.Name) == 0 {
			resourceOptions.Name = args[0]
		}
		if len(args) > 1 {
			ats, err := attrs.ParseArgs(args[1:]...)
			if err != nil {
				return err
			}
			resourceOptions.Attrs = ats
		}

		if err := run.WithNew(resource.New(resourceOptions.Options)); err != nil {
			return err
		}
		return run.Run()
	},
}

ResourceCmd generates a new actions/resource file and a stub test.

var TaskCmd = &cobra.Command{
	Use:     "task [name]",
	Aliases: []string{"t", "grift"},
	Short:   "Generate a grift task",
	RunE: func(cmd *cobra.Command, args []string) error {
		run := genny.WetRunner(context.Background())
		if taskOptions.dryRun {
			run = genny.DryRunner(context.Background())
		}

		opts := taskOptions.Options
		opts.Args = args
		g, err := grift.New(opts)
		if err != nil {
			return err
		}
		run.With(g)

		pwd, _ := os.Getwd()
		g, err = gogen.Fmt(pwd)
		if err != nil {
			return err
		}
		run.With(g)

		return run.Run()
	},
}

TaskCmd is the command called with the generate grift cli.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier