gencmd

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Set contains providers for DI.

Functions

func ProvideGrapiCtx

func ProvideGrapiCtx(ctx *Ctx) *grapicmd.Ctx

func ProvideTemplateFS

func ProvideTemplateFS(cmd *Command) http.FileSystem

Types

type App

type App struct {
	Generator Generator
	UI        cli.UI
}

App contains dependencies to execute a generator.

type Command

type Command struct {
	// Use, Short, Long, Example and Args are pass-through into *cobra.Command object.
	Use     string
	Short   string
	Long    string
	Example string
	Args    cobra.PositionalArgs

	// BuildParams returns parameters to generate/destroy files(required).
	BuildParams func(c *Command, args []string) (interface{}, error)

	// PreRun is executed in *cobra.Command.PreRunE.
	PreRun func(c *Command, args []string) error

	// PostRun is executed in *cobra.Command.PostRunE.
	PostRun func(c *Command, args []string) error

	// ShouldRun is executed for each generated files. When it returns false, the file will be skipped.
	ShouldRun ShouldRunFunc

	// ShouldInsideApp will disable the command when a current working directory is not inside of a grapi project.
	ShouldInsideApp bool

	// TemplateFS contains file templates(required).
	TemplateFS http.FileSystem
	// contains filtered or unexported fields
}

Command represents a subcommand of a generator plugin. It will be converted to a *cobra.Command object internally.

func (*Command) Ctx

func (c *Command) Ctx() *Ctx

Ctx returns the context object.

func (*Command) Flags

func (c *Command) Flags() *pflag.FlagSet

Flags returns a FlagSet that applies to this commmand.

type CreateAppFunc

type CreateAppFunc func(*Command) (*App, error)

CreateAppFunc initializes dependencies.

type Ctx

type Ctx struct {
	*grapicmd.Ctx

	CreateAppFunc CreateAppFunc
}

Ctx defines a context of a generator.

func ProvideCtx

func ProvideCtx(cmd *Command) *Ctx

func (*Ctx) CreateApp

func (c *Ctx) CreateApp(cmd *Command) (*App, error)

CreateApp initializes dependencies.

type Entry

type Entry struct {
	File
	Template File
}

Entry represents a file that will be generated.

type Executor

type Executor interface {
	Command() *cobra.Command
	Execute() error
	MustExecute()
}

func New

func New(
	name string,
	generateCmd *Command,
	destroyCmd *Command,
	opts ...Option,
) Executor

New creates an Executor instnace.

type File

type File struct {
	Path string
	Body string
}

File represents a file content.

type Generator

type Generator interface {
	Generate(params interface{}) error
	Destroy(params interface{}) error
}

func NewGenerator

func NewGenerator(
	fs afero.Fs,
	ui cli.UI,
	rootDir cli.RootDir,
	templateFS http.FileSystem,
	shouldRunFunc ShouldRunFunc,
) Generator

type Option

type Option func(*Ctx)

Option configures a command context.

func WithCreateAppFunc

func WithCreateAppFunc(f CreateAppFunc) Option

WithCreateAppFunc specifies a dependencies initializer.

func WithGrapiCtx

func WithGrapiCtx(gctx *grapicmd.Ctx) Option

WithGrapiCtx specifies a grapi command context.

type ShouldRunFunc

type ShouldRunFunc func(e *Entry) bool

func ProvideShouldRun

func ProvideShouldRun(cmd *Command) ShouldRunFunc

type TemplateString

type TemplateString string

TemplateString is a compilable string with text/template package

func (TemplateString) Compile

func (s TemplateString) Compile(v interface{}) (string, error)

Compile generates textual output applied a parsed template to the specified values

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL