skeleton

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSynopsis is default synopsis message.
	DefaultSynopsis = ""

	// DefaultHelp is default help message.
	DefaultHelp = ""
)
View Source
const (
	// DefaultVersion is default appliaction version.
	DefaultVersion = "0.1.0"

	// DefaultDescription is default application description.
	DefaultDescription = ""
)
View Source
const (
	TypeStringInt    = "int"
	TypeStringBool   = "bool"
	TypeStringString = "string"
)

TypeString represents type as string

Variables

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

CommonTemplates is collection of templates which are used all frameworks.

View Source
var Frameworks = []*Framework{
	{
		Name:     "mitchellh_cli",
		AltNames: []string{"mitchellh"},
		URL:      "https://github.com/mitchellh/cli",
		Description: `mitchellh/cli cli is a library for implementing powerful command-line interfaces in Go.
cli is the library that powers the CLI for Packer, Serf, and Consul.
`,
		BaseTemplates: []Template{
			{"resource/tmpl/mitchellh_cli/main.go.tmpl", "main.go"},
			{"resource/tmpl/mitchellh_cli/version.go.tmpl", "version.go"},
			{"resource/tmpl/mitchellh_cli/cli.go.tmpl", "cli.go"},
			{"resource/tmpl/mitchellh_cli/commands.go.tmpl", "commands.go"},
			{"resource/tmpl/mitchellh_cli/command/meta.go.tmpl", "command/meta.go"},
			{"resource/tmpl/mitchellh_cli/command/version.go.tmpl", "command/version.go"},
		},
		CommandTemplates: []Template{
			{"resource/tmpl/mitchellh_cli/command/command.go.tmpl", "command/{{ .Name }}.go"},
			{"resource/tmpl/mitchellh_cli/command/command_test.go.tmpl", "command/{{ .Name }}_test.go"},
		},
	},

	{
		Name:     "codegangsta_cli",
		AltNames: []string{"codegangsta"},
		URL:      "https://github.com/codegangsta/cli",
		Description: `codegangsta/cli is simple, fast, and fun package for building command line apps in Go.
The goal is to enable developers to write fast and distributable command line applications in an expressive way.
`,
		BaseTemplates: []Template{
			{"resource/tmpl/codegangsta_cli/main.go.tmpl", "main.go"},
			{"resource/tmpl/codegangsta_cli/version.go.tmpl", "version.go"},
			{"resource/tmpl/codegangsta_cli/commands.go.tmpl", "commands.go"},
		},
		CommandTemplates: []Template{
			{"resource/tmpl/codegangsta_cli/command/command.go.tmpl", "command/{{ .Name }}.go"},
			{"resource/tmpl/codegangsta_cli/command/command_test.go.tmpl", "command/{{ .Name }}_test.go"},
		},
	},

	{
		Name: "go_cmd",
		URL:  "https://github.com/golang/go/tree/master/src/cmd/go",
		Description: `
`,
		BaseTemplates: []Template{
			{"resource/tmpl/go_cmd/main.go.tmpl", "main.go"},
		},
		CommandTemplates: []Template{
			{"resource/tmpl/go_cmd/command.go.tmpl", "{{ .Name }}.go"},
			{"resource/tmpl/go_cmd/command_test.go.tmpl", "{{ .Name }}_test.go"},
		},
	},

	{
		Name: "bash",
		URL:  "",
		Description: `
`,
		BaseTemplates: []Template{
			{"resource/tmpl/bash/main.sh.tmpl", "{{ .Name }}.sh"},
		},
		CommandTemplates: []Template{},
		Hide:             true,
	},

	{
		Name:        "flag",
		AltNames:    []string{},
		URL:         "https://golang.org/pkg/flag/",
		Description: `Package flag implements command-line flag parsing.`,
		BaseTemplates: []Template{
			{"resource/tmpl/flag/main.go.tmpl", "main.go"},
			{"resource/tmpl/flag/version.go.tmpl", "version.go"},
			{"resource/tmpl/flag/cli.go.tmpl", "cli.go"},
			{"resource/tmpl/flag/cli_test.go.tmpl", "cli_test.go"},
		},
		CommandTemplates: []Template{},
	},
}

Frameworks is collection of Framework.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Name is command name.
	Name string

	// FunctionName is name used for function decralation.
	// in generating souce code. Name may contain invalid charactor
	// like `-` so it holds valid name for it.
	FunctionName 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

	// debugOutput is injected to command function
	// and generate for debugging purpose.
	// TODO: https://github.com/BurntSushi/toml/pull/90
	DebugOutput string `toml:",omitempty"`
}

Command store command meta information.

func (*Command) Fix added in v0.2.3

func (c *Command) Fix() error

Fix fixes user input

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

	// FrameworkStr is framework name to use.
	FrameworkStr string `toml:"Framework"`
}

Executable store executable meta information.

func NewExecutable added in v0.2.2

func NewExecutable() *Executable

NewExecutable is constructor of Executable struct.

func (*Executable) Fix added in v0.2.3

func (e *Executable) Fix() error

Fix fixes user inputs for using

func (*Executable) Overwrite added in v0.2.2

func (e *Executable) Overwrite(key string, v interface{}) error

Overwrite overwrites provided value with default value.

func (*Executable) Validate added in v0.2.2

func (e *Executable) Validate() (errs []error)

Validate validates Executalbe has required field or not. If not returns, errors as slice.

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

	// VariableName is variable name which is usded for
	// holding a flag value in generating source code
	VariableName 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
}

Flag stores flag meta informations

func (*Flag) Fix

func (f *Flag) Fix() error

Fix fixed user input for templating.

type Framework

type Framework struct {
	// Name is framework name
	Name string

	// AltName is alternative name which represent Framework
	AltNames []string

	// Description is description of framework
	Description string

	// URL is framework project URL
	URL string

	// BaseTemplates
	BaseTemplates []Template

	// CommandTemplate
	CommandTemplates []Template

	// If Hide is true, `list` command doesn't show
	// this framework
	Hide bool
}

Framework represents framework

func FrameworkByName added in v0.2.1

func FrameworkByName(name string) (*Framework, error)

FrameworkByName retuns Framework

type Skeleton

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

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

	Framework  *Framework
	Executable *Executable

	// ArtifactCh is channel for info output
	ArtifactCh chan string

	// ErrCh is channel for error output
	ErrCh chan error

	// Verbose enables logging output below INFO
	Verbose bool

	// LogWriter
	LogWriter io.Writer
}

Skeleton stores meta data of skeleton

func (*Skeleton) Debugf added in v0.2.1

func (s *Skeleton) Debugf(format string, args ...interface{})

Debugf outputs debug infomation

func (*Skeleton) Generate

func (s *Skeleton) Generate() <-chan struct{}

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
}

Template stores meta data of template

func (*Template) Exec

func (t *Template) Exec(data interface{}) (string, 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