skeleton

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CLI with commands
	Framework_go_cmd = 100 + iota
	Framework_codegangsta_cli
	Framework_mitchellh_cli

	// CLI only with flag
	Framework_flag = 1000 + iota
)

Variables

View Source
var (
	CommonTemplates = []Template{
		{"resource/tmpl/common/CHANGELOG.md.tmpl", "CHANGELOG.md"},
		{"resource/tmpl/common/README.md.tmpl", "README.md"},
	}
)

Functions

func CommandTemplates

func CommandTemplates(framework int) (Template, Template)

CommandTempaltes returns command Tempalte based on framework ID. The first return value is command Tempalte. The second return value is command test Tempalte.

func Framework

func Framework(name string) (int, error)

Framework returns framework ID (unique variable in gcli) from name string. If not match any framework, it returns error.

Types

type Command

type Command struct {
	Name string

	// Flags are flag for the command
	Flags []Flag

	// Synopsis is short help message of the command
	Synopsis string

	// Help is long help message of the command
	Help string
}

Command store command meta information

type Executable

type Executable struct {
	// Name is executable name
	Name string

	// Owner is owner of the executable
	Owner string

	// Commands are commands of the executable
	Commands []Command

	// Flags are flags of the executable
	Flags []Flag

	// Version is initial version
	Version string

	// Description is description of the executable
	Description string
}

type Flag

type Flag struct {
	// Name is flag name, this is used for flag variable name in generated code.
	// Name is equal to titled LongName.
	Name string

	// LongName is long form of the flag name.
	// This must be provided by user
	LongName string

	// ShortName is short form of flag name.
	// This is generated automatically from LongName
	ShortName string

	// TypeString is flag type. This must be provided by user
	TypeString string

	// Default is default value.
	// This is automatically generated from TypeString
	Default interface{}

	// Description is help message of the flag.
	Description string
}

func (*Flag) Fix

func (f *Flag) Fix() error

Fix fixed user input for templating.

type Skeleton

type Skeleton struct {
	// Path is where skeleton is generated.
	Path string

	// Framework represent which cli package is used.
	// Framework ID is defined on framework_tempalte.go
	Framework int

	// If WithTest is true, also generate test code.
	SkipTest bool

	Executable *Executable
}

func (*Skeleton) Generate

func (s *Skeleton) Generate() <-chan error

Generate generates code files from tempalte files.

type Template

type Template struct {
	// Path is the path to this template.
	Path string

	// OutputPathTmpl is the template for outputPath.
	OutputPathTmpl string
}

func FrameworkTemplates

func FrameworkTemplates(framework int) []Template

FrameworkTempaltes returns framework Template based on framework ID.

func (*Template) Exec

func (t *Template) Exec(data interface{}) error

Exec evaluate this template and write it to provided file. At First, it reads template content. Then, it generates output file path from output path template and its data. Then, it creates directory if not exist from output path. Then, it opens output file. Finally, it evaluates template contents and generate it to output file. If output file is gocode, run go fmt.

It returns an error if any.

Jump to

Keyboard shortcuts

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