Documentation
¶
Overview ¶
Package skeleton provides functionality to interact with local and remote skeleton repositories and to fetch the configuration values of any given skeleton.
Index ¶
- Constants
- Variables
- func Create(path string) error
- func CreateRepository(path, skeletonName string) error
- func FindSkeletonDir(path string) (string, error)
- func IsInsideSkeletonDir(path string) (bool, error)
- type Config
- type File
- type Info
- type Loader
- type Reference
- type Repository
- type RepositoryInfo
- type Skeleton
Constants ¶
const (
// ConfigFileName is the name of the skeleton's config file.
ConfigFileName = ".kickoff.yaml"
)
Variables ¶
var ( // ErrDirNotFound indicates that a skeleton directory was not found. ErrDirNotFound = errors.New("skeleton dir not found") // ErrNoRepositories is returned by NewRepositoryAggregate if no repositories are // configured. ErrNoRepositories = errors.New("no skeleton repositories configured") )
var ( // LocalCache holds the path to the local repository cache. This is platform // specific. LocalCache = configdir.LocalCache("kickoff", "repositories") )
Functions ¶
func Create ¶
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 CreateRepository ¶
CreateRepository creates a new skeleton repository at path and initializes it with a skeleton located in a subdir named skeletonName.
func FindSkeletonDir ¶
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 ¶
IsInsideSkeletonDir returns true if path is inside a skeleton dir. If path is a skeleton dir itself, this will return false.
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 ¶
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
// AbsPath is the absolute path to the file on disk.
AbsPath string
// Inherited indicates whether the file was inherited from a parent
// skeleton or not.
Inherited bool
// Info is the os.FileInfo for the file
Info os.FileInfo
}
File contains paths and other information about a skeleton file, e.g. whether it was inherited from a parent skeleton or not.
type Info ¶
type Info struct {
Name string
Path string
Repo *RepositoryInfo
}
Info holds information about a skeleton.
func (*Info) LoadConfig ¶
Config loads the skeleton config for the info.
type Loader ¶
type Loader struct {
Repo Repository
}
Loader loads skeletons from a repository.
func NewLoader ¶
func NewLoader(repo Repository) *Loader
NewLoader creates a new *Loader value which will use repo to load skeletons.
func NewRepositoryAggregateLoader ¶
NewRepositoryAggregateLoader creates a new *Loader value which can load skeletons from multiple repositories. The repos map must contain repo names as keys and repo urls as values. Returns an error if the passed in map of repositories is invalid.
func NewSingleRepositoryLoader ¶
NewSingleRepositoryLoader creates a new *Loader value which can load skeletons from the single repository at url. Returns an error if opening the repository fails.
func (*Loader) LoadSkeleton ¶
LoadSkeleton loads the skeleton with name from the repository. The returned skeleton already includes the recursively merged list of files and values from potential parents.
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 Repository ¶
type Repository interface {
// SkeletonInfo obtains the info for the skeleton with name or an error if the
// skeleton does not exist within the repository.
SkeletonInfo(name string) (*Info, error)
// SkeletonInfos returns infos for all skeletons available in the repository.
// Returns any error that may occur while traversing the directory.
SkeletonInfos() ([]*Info, error)
}
Repository is the interface for a skeleton repository.
func NewRepositoryAggregate ¶
func NewRepositoryAggregate(repos map[string]string) (Repository, error)
NewRepositoryAggregate creates a new Repository which will lookup skeletons in the repositories provided in the repos map. The map maps an arbitrary repository name to an url.
func OpenRepository ¶
func OpenRepository(url string) (Repository, error)
OpenRepository opens a repository and returns it. If url points to a remote repository it will be looked up in the local cache and reused if possible. If the repository is not in the cache it will be cloned. Open will automatically checks out the revision provided in the url. Returns any errors that occur while parsing the url opening the repository directory or during git actions.
type RepositoryInfo ¶
type RepositoryInfo struct {
Local bool
Name string
Revision string
Path string
Scheme string
User string
Host string
}
RepositoryInfo holds information about a skeleton repository.
func ParseRepositoryURL ¶
func ParseRepositoryURL(rawurl string) (*RepositoryInfo, error)
ParseRepositoryURL parses a raw repository url into a repository info.
func (*RepositoryInfo) LocalPath ¶
func (i *RepositoryInfo) LocalPath() string
LocalPath returns the local path to a repository. For local repositories this is just the actual path on disk, for remote repositories this returns a path within the LocalCache directory.
func (*RepositoryInfo) SkeletonsDir ¶
func (i *RepositoryInfo) SkeletonsDir() string
SkeletonsDir returns the local path of the skeletons dir within the repository.
func (*RepositoryInfo) String ¶
func (i *RepositoryInfo) String() string
String implements fmt.Stringer.
func (*RepositoryInfo) Validate ¶
func (i *RepositoryInfo) Validate() error
Validate validates a repository info. Returns an error if i does not describe a valid skeleton repository.
type Skeleton ¶
type Skeleton struct {
// Description is the skeleton description text obtained from the skeleton
// config.
Description string
// Parent is a reference to the parent skeleton. Is nil if the skeleton has
// no parent.
Parent *Skeleton
// Info is the skeleton info that was used to load the skeleton.
Info *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
// Values are the template values from the skeleton's config merged with
// those of it's parents (if any).
Values template.Values
}
Skeleton is the representation of a skeleton returned by Load() with all references to parent skeletons (if any) resolved.
func Load ¶
Load loads a skeleton based on its *Info. It will recursively load all parent skeletons (if any) and merge all parent values and files into the resulting *Skeleton.
func Merge ¶
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.