Documentation
¶
Index ¶
- Constants
- Variables
- func Load(path string, v interface{}) error
- func Save(path string, v interface{}) error
- func SaveConfig(path string, config *Config) error
- type BufferedFile
- type Config
- type Defaulter
- type ProjectConfig
- type RepoRef
- type Repository
- type Skeleton
- type SkeletonConfig
- type SkeletonRef
- type ValidationError
- type Validator
Constants ¶
const ( // DefaultConfigFileName is the default name kickoff's user config file. DefaultConfigFileName = "config.yaml" // SkeletonConfigFileName is the name of the file that is searched to // file skeletons and their config. SkeletonConfigFileName = ".kickoff.yaml" // SkeletonTemplateExtension is the file extension for template files // within kickoff skeletons. Although kickoff template files are // gotemplates, we must not use .tmpl as user may want to include their own // gotemplate files in skeletons which must not be evaluated by kickoff, // hence we use .skel to avoid issues here. SkeletonTemplateExtension = ".skel" // SkeletonsDir is the subdirectory of a repository where skeletons // can be found. SkeletonsDir = "skeletons" )
const ( // DefaultProjectHost denotes the default git host that is passed to // templates so that project related urls can be rendered in files like // READMEs. DefaultProjectHost = "github.com" // DefaultRepositoryName is the name of the default skeleton repository. DefaultRepositoryName = "default" // DefaultSkeletonName is the name of the default skeleton in a repository. DefaultSkeletonName = "default" )
const ( // EnvKeyLogLevel configures custom path to the kickoff config file. EnvKeyConfig = "KICKOFF_CONFIG" // EnvKeyEditor configures the command used to edit config files. EnvKeyEditor = "KICKOFF_EDITOR" // EnvKeyLogLevel configures the log level. EnvKeyLogLevel = "KICKOFF_LOG_LEVEL" // EnvKeyNoUpdateCheck disables update checks. EnvKeyNoUpdateCheck = "KICKOFF_NO_UPDATE_CHECK" )
Variables ¶
var ( // ErrMergeEmpty is returned by MergeSkeletons if no skeletons were // passed. ErrMergeEmpty = errors.New("cannot merge empty list of skeletons") // ErrEmptyRepositoryURL is returned if ParseRepoRef is invoked with an // empty URL. ErrEmptyRepositoryURL = errors.New("empty repository url") )
var ( // LocalConfigDir points to the user's local configuration dir which is // platform specific. LocalConfigDir = configdir.LocalConfig("kickoff") // DefaultConfigPath holds the default kickof config path in the user's // local config directory. DefaultConfigPath = filepath.Join(LocalConfigDir, DefaultConfigFileName) // DefaultRepositoryURL is the url of the default skeleton repository if // the user did not configure anything else. DefaultRepositoryURL = "https://github.com/martinohmann/kickoff-skeletons" // LocalCacheDir points to the user's local cache dir which is // platform specific. LocalCacheDir = configdir.LocalCache("kickoff") LocalRepositoryCacheDir = filepath.Join(LocalCacheDir, "repositories") )
Functions ¶
func Load ¶
Load loads a file from path into v. Returns an error if reading the file fails. Does not perform any defaulting or validation.
func SaveConfig ¶
SaveConfig saves config to path.
Types ¶
type BufferedFile ¶
type BufferedFile struct {
// RelPath is the file path relative to root directory of the skeleton.
// This is used to construct the path for the file relative to the the
// target project directory.
RelPath string `json:"relPath"`
// Content holds the file contents.
Content []byte `json:"content"`
// Mode is the os.Mode for the file. This provides information about the
// type of file, e.g. whether it is a directory or not.
Mode os.FileMode `json:"mode"`
// SkeletonRef contains the ref to the skeleton the file originated from or
// nil if it does not belong to a specific skeleton. Used to keep track of
// file origins during skeleton composition.
SkeletonRef *SkeletonRef `json:"-"`
}
BufferedFile is a file that is already buffered in memory.
func MergeFiles ¶ added in v0.2.0
func MergeFiles(lhs, rhs []*BufferedFile) []*BufferedFile
MergeFiles merges two lists of files. Files in the rhs list take precedence over files in the lhs list with the same name.
type Config ¶
type Config struct {
// Project holds default configuration values like default project host and
// owner which are the same for new projects most of the time. Can be
// overridden on project creation.
Project ProjectConfig `json:"project,omitempty"`
// Repositories holds a map of configured repositories to search for
// available skeletons. Keys are the locally configured names for these
// repositories.
Repositories map[string]string `json:"repositories,omitempty"`
// Values holds user-defined values that get merged on to of skeleton
// values.
Values template.Values `json:"values,omitempty"`
}
Config describes the schema for the local user-defined kickoff configuration file.
func DefaultConfig ¶ added in v0.2.0
func DefaultConfig() *Config
DefaultConfig returns the default config.
func LoadConfig ¶
Load loads the config from path and returns it.
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults applies default values to the config.
type Defaulter ¶
type Defaulter interface {
// ApplyDefaults sets unset fields of the data structure to its default
// values which might not necessarily be the zero value.
ApplyDefaults()
}
Defaulter can set defaults for unset fields.
type ProjectConfig ¶
type ProjectConfig struct {
// Host holds the default git host's domain, e.g. 'github.com'.
Host string `json:"host,omitempty"`
// Owner holds the default repository owner name.
Owner string `json:"owner,omitempty"`
// License holds the name of the default open source license.
License string `json:"license,omitempty"`
// Gitignore holds a comma-separated list of gitignore templates, e.g.
// 'go,hugo'.
Gitignore string `json:"gitignore,omitempty"`
}
ProjectConfig contains project specific configuration like git host, owner and project name.
func (*ProjectConfig) ApplyDefaults ¶
func (p *ProjectConfig) ApplyDefaults()
ApplyDefaults applies defaults to unset fields. If the Owner field is empty ApplyDefaults will attempt to fill it with the git config values of github.user or user.name if exists.
func (*ProjectConfig) Validate ¶
func (c *ProjectConfig) Validate() error
Validate implements the Validator interface.
type RepoRef ¶
type RepoRef struct {
// Name holds the optional local name for the repository.
Name string `json:"name,omitempty"`
// URL to the repository, e.g. 'https://github.com/foobar/baz' or
// `/some/local/path`.
URL string `json:"url,omitempty"`
// Path is the path to a local repository.
Path string `json:"path,omitempty"`
// Revision holds the revision of the remote git repository to checkout.
// This can be a branch, tag or commit SHA.
Revision string `json:"revision,omitempty"`
}
RepoRef holds information about a skeleton repository's location.
func ParseRepoRef ¶
ParseRepoRef parses a raw repository url and returns a repository ref describing a local or remote skeleton repository. The rawurl parameter must be either a local path or a remote url to a git repository. Remote url may optionally include a `revision` query parameter. If absent, `master` will be assumed. Returns an error if url does not match any of the criteria mentioned above.
func (*RepoRef) IsEmpty ¶
IsEmpty return true if l is empty, that is: it neither describes a local nor remote repository.
func (*RepoRef) IsLocal ¶ added in v0.2.0
IsLocal returns true if the repo ref describes a local repository.
func (*RepoRef) LocalPath ¶ added in v0.2.0
LocalPath returns the local path for the repository. If r points to a remote repo this returns the local cache dir for the remote. Causes a fatal error if the absolute path cannot be constructed.
func (*RepoRef) SkeletonPath ¶ added in v0.2.0
SkeletonPath returns the path to a skeletons within the repository. This is always a local path even if the repository is remote.
func (*RepoRef) SkeletonsPath ¶ added in v0.2.0
SkeletonsPath returns the path to the skeletons dir within the repository. This is always a local path even if the repository is remote.
type Repository ¶
type Repository interface {
// GetSkeleton retrieves information about a skeleton from the repository.
// Returns an error of type SkeletonNotFoundError if the named skeleton was
// not found in the repository.
GetSkeleton(name string) (*SkeletonRef, error)
// ListSkeletons retrieves information about all skeletons in the
// repository. If the repository is empty, ListSkeletons will return an
// empty slice.
ListSkeletons() ([]*SkeletonRef, error)
// LoadSkeleton loads the skeleton with name from given repository. Returns
// an error if loading the skeleton fails.
LoadSkeleton(name string) (*Skeleton, error)
// CreateSkeleton creates a new skeleton with name in the referenced
// repository. Skeleton creation will fail with an error if ref does not
// reference a local repository. 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.
CreateSkeleton(name string) (*SkeletonRef, error)
}
Repository is the interface for a skeleton repository.
type Skeleton ¶
type Skeleton struct {
// Description is the skeleton description text obtained from the skeleton
// config.
Description string `json:"description,omitempty"`
// Ref holds the information about the location that was used to load the
// skeleton. May be nil if the skeleton is the merged result of composing
// multiple skeletons.
Ref *SkeletonRef `json:"ref,omitempty"`
// The Files slice contains a sorted list of files that are present in the
// skeleton.
Files []*BufferedFile `json:"files,omitempty"`
// Values are the template values from the skeleton's metadata.
Values template.Values `json:"values,omitempty"`
}
Skeleton is the representation of a skeleton loaded from a skeleton repository.
func MergeSkeletons ¶
MergeSkeletons 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 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) Merge ¶
Merge merges two skeletons. The skeletons are merged left to right with template values, skeleton files and skeleton ref of the rightmost skeleton taking preference over already existing values. Template values are recursively merged and may cause errors on type mismatch. The original skeletons are not altered.
type SkeletonConfig ¶
type SkeletonConfig struct {
// Description holds a decription of the skeleton that can give some more
// user-defined hints on the skeleton usage, e.g. interesting values to
// tweak.
Description string `json:"description,omitempty"`
// Values holds user-defined values available in .skel templates.
Values template.Values `json:"values,omitempty"`
}
SkeletonConfig describes the schema of a skeleton's .kickoff.yaml that is bundled together with the skeleton.
func LoadSkeletonConfig ¶
func LoadSkeletonConfig(path string) (*SkeletonConfig, error)
LoadSkeletonConfig loads the skeleton config from path and returns it.
type SkeletonRef ¶
type SkeletonRef struct {
// Name of the skeleton. May include slashes if the skeleton is organized
// in a subdirectory relative to the skeletons root.
Name string `json:"name"`
// Path contains the local path to the skeleton.
Path string `json:"path"`
// Repository references the repository where the skeleton can be found.
Repo *RepoRef `json:"repo"`
}
SkeletonRef holds information about the location of a skeleton.
func (*SkeletonRef) LoadConfig ¶
func (r *SkeletonRef) LoadConfig() (*SkeletonConfig, error)
LoadConfig loads the skeleton config for the info.
func (*SkeletonRef) Validate ¶
func (r *SkeletonRef) Validate() error
Validate implements the Validator interface.
type ValidationError ¶
ValidationError wraps all errors that occur during validation.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error