skeleton

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package skeleton contains types that define the structure of a skeleton and its config. It also provides helpers to find, create and merge skeletons.

Index

Constants

View Source
const ConfigFileName = ".kickoff.yaml"

ConfigFileName is the name of the skeleton's config file.

Variables

View Source
var (
	// ErrDirNotFound indicates that a skeleton directory was not found.
	ErrDirNotFound = errors.New("skeleton dir not found")

	// ErrMergeEmpty is returned by Merge if no skeletons were passed.
	ErrMergeEmpty = errors.New("cannot merge empty list of skeletons")
)

Functions

func Create

func Create(path string) error

Create creates a new skeleton at path. The created skeleton contains an example .kickoff.yaml and example README.md.skel as starter. Returns an error if creating path or writing any of the files fails.

func FindSkeletonDir

func FindSkeletonDir(path string) (string, error)

FindSkeletonDir finds the skeleton dir path resides in. It walk up the filesystem tree and checks for each parent if it is a skeleton dir and returns its path if the check was successful. Returns ErrDirNotFound if path does not reside within a skeleton dir or one of its subdirectories. Returns any other errors that may occur while traversing the filesystem tree.

func IsInsideSkeletonDir

func IsInsideSkeletonDir(path string) (bool, error)

IsInsideSkeletonDir returns true if path is inside a skeleton dir. If path is a skeleton dir itself, this will return false.

func IsSkeletonDir

func IsSkeletonDir(dir string) (bool, error)

IsSkeletonDir returns true if dir is a skeleton dir. Skeleton dirs are detected by the fact that they contain a .kickoff.yaml file.

Types

type Config

type Config struct {
	Description string          `json:"description,omitempty"`
	Parent      *Reference      `json:"parent,omitempty"`
	Values      template.Values `json:"values"`
}

Config describes the schema of a skeleton's .kickoff.yaml.

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig loads the skeleton config from path and returns it.

type File

type File struct {
	// RelPath is the file path relative to root directory of the skeleton.
	RelPath string `json:"relPath"`

	// AbsPath is the absolute path to the file on disk.
	AbsPath string `json:"absPath"`

	// Info is the os.FileInfo for the file
	Info os.FileInfo `json:"-"`
}

File contains paths and other information about a skeleton file, e.g. whether it was inherited from a parent skeleton or not.

func (*File) IsTemplate

func (f *File) IsTemplate() bool

IsTemplate implements project.Source.

func (*File) Mode

func (f *File) Mode() os.FileMode

Mode implements project.Source.

func (*File) Path

func (f *File) Path() string

Path implements project.Source.

func (*File) Reader

func (f *File) Reader() (io.Reader, error)

Reader implements project.Source.

type Info

type Info struct {
	Name string    `json:"name"`
	Path string    `json:"path"`
	Repo *RepoInfo `json:"repo"`
}

Info holds information about the location of a skeleton.

func (*Info) LoadConfig

func (i *Info) LoadConfig() (Config, error)

LoadConfig loads the skeleton config for the info.

func (*Info) String

func (i *Info) String() string

String implements fmt.Stringer.

type Reference

type Reference struct {
	RepositoryURL string `json:"repositoryURL,omitempty"`
	SkeletonName  string `json:"skeletonName"`
}

Reference is a reference to a skeleton in a specific repository.

type RepoInfo

type RepoInfo struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	URL      string `json:"url,omitempty"`
	Revision string `json:"revision,omitempty"`
}

RepoInfo holds information about a skeleton repository.

func (*RepoInfo) FindSkeletons

func (i *RepoInfo) FindSkeletons() ([]*Info, error)

FindSkeletons recursively finds all skeletons in dir and attaches i to the results. Returns any error that may occur while traversing dir.

func (*RepoInfo) IsRemote

func (i *RepoInfo) IsRemote() bool

IsRemote returns true if the repo info describes a remote repository.

type Skeleton

type Skeleton struct {
	// Description is the skeleton description text obtained from the skeleton
	// config.
	Description string `json:"description,omitempty"`

	// Parent is a reference to the parent skeleton. Is nil if the skeleton has
	// no parent.
	Parent *Skeleton `json:"parent,omitempty"`

	// Info is the skeleton info that was used to load the skeleton.
	Info *Info `json:"info"`

	// The Files slice contains a merged and sorted list of file references
	// that includes all files from the skeleton and its parents (if any).
	Files []*File `json:"files,omitempty"`

	// Values are the template values from the skeleton's config merged with
	// those of it's parents (if any).
	Values template.Values `json:"values,omitempty"`
}

Skeleton is the representation of a skeleton loaded from a skeleton repository.

func Merge

func Merge(skeletons ...*Skeleton) (*Skeleton, error)

Merge merges multiple skeletons together and returns a new *Skeleton. The skeletons are merged left to right with template values, skeleton files and skeleton info of the rightmost skeleton taking preference over already existing values. Template values are recursively merged and may cause errors on type mismatch. The resulting *Skeleton will have the second-to-last skeleton set as its parent, the second-to-last will have the third-to-last as parent and so forth. The original skeletons are not altered. If only one skeleton is passed it will be returned as is without modification. Passing a slice with length of zero will return in an error.

func (*Skeleton) String

func (s *Skeleton) String() string

String implements fmt.Stringer.

Directories

Path Synopsis
Package filetree provides a tree type which can be used to build and print file trees of skeletons.
Package filetree provides a tree type which can be used to build and print file trees of skeletons.

Jump to

Keyboard shortcuts

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