Documentation ¶
Overview ¶
The snippet package provides functions and types for working with snippets. A snippet is a file containing a fragment of Go code suitable to be copied into a larger program. The snippet files are annotated with semantic comments to provide documentation about the correct usage of the snippet. These semantic comments can also be interpreted to provide some checking of the correct usage.
Index ¶
Constants ¶
const ( // these are named parts of the snippet for listing NamePart = "name" PathPart = "path" TextPart = "text" DocsPart = "note" ImportPart = "imports" ExpectPart = "expects" FollowPart = "follows" TagPart = "tag" // these correspond to semantic comments in the snippet CommentStr = "snippet:" NoteStr = DocsPart + ":" ImportStr = ImportPart + ":" ExpectStr = ExpectPart + ":" AfterStr = FollowPart + ":" TagStr = TagPart + ":" )
Variables ¶
This section is empty.
Functions ¶
func AltPartNames ¶ added in v1.2.0
AltPartNames returns a slice of alternative names for the given part. Note that the slice may be empty.
func List ¶
List will read all of the snippet directories and show the available snippet files. Any errors are recorded in errs.
func ValidParts ¶ added in v1.1.0
ValidParts returns a map which has an entry for all the valid parts of a snippet with a brief description of the part and how it is used.
Types ¶
type Cache ¶
Cache holds a collection of snippets by name
func (*Cache) Add ¶
Add will check that the snippet is not already in the cache and if not it will search for the snippet file in the snippetDirs, parse the file and generate a snippet which it will then store in the cache. It returns the snippet and any error; if the error is non-nil the snippet will be nil.
type ListCfg ¶ added in v1.1.0
ListCfg holds the configuration for controlling the listing of snippets
func NewListCfg ¶ added in v1.1.0
func NewListCfg(w io.Writer, dirs []string, errs *errutil.ErrMap, opts ...ListCfgOptFunc, ) (*ListCfg, error)
NewListCfg returns a new ListCfg holding the configuration for snippet listing.
type ListCfgOptFunc ¶ added in v1.1.0
ListCfgOptFunc is a function which sets some part of a ListCfg structure
func HideIntro ¶ added in v1.1.0
func HideIntro(val bool) ListCfgOptFunc
HideIntro returns a ListCfgOptFunc which will set up the ListCfg value to the given value. Setting it to true will suppress the printing of the snippet part names before the values.
func SetConstraints ¶ added in v1.1.0
func SetConstraints(vals ...string) ListCfgOptFunc
SetConstraints returns a ListCfgOptFunc which will set on a ListCfg value the constraints on the snippets to be shown.
func SetParts ¶ added in v1.1.0
func SetParts(vals ...string) ListCfgOptFunc
SetParts returns a ListCfgOptFunc which will set on a ListCfg value the parts of the snippets to be shown.
func SetTags ¶ added in v1.1.0
func SetTags(vals ...string) ListCfgOptFunc
SetTags returns a ListCfgOptFunc which will set on a ListCfg value the tags of the snippets to be shown.
type S ¶
type S struct {
// contains filtered or unexported fields
}
S records the details of the snippet
func (S) Expects ¶
Expects returns the list of other snippets that are expected to be used if this snippet is used.
func (S) Follows ¶
Follows returns the list of other snippets that this snippet should come after in any code that uses it.
func (S) Imports ¶
Imports returns the list of packages that are expected to be imported if this snippet is used.