buffalo: github.com/gobuffalo/buffalo/buffalo/cmd/generate Index | Files

package generate

import "github.com/gobuffalo/buffalo/buffalo/cmd/generate"

Index

Package Files

action.go mailer.go resource.go task.go

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 errors.New("you must provide a name")
        }
        actionOptions.Name = args[0]
        if len(args) == 1 {
            return errors.New("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 errors.New("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.

Package generate imports 14 packages (graph) and is imported by 22 packages. Updated 2019-06-26. Refresh now. Tools for package owners.