Documentation
¶
Index ¶
- func WithOverwrite(p *Project) error
- type Action
- type ActionType
- type Destination
- type Logger
- type Option
- func WithExtraFile(r io.Reader, path string, mode os.FileMode) Option
- func WithExtraValues(values template.Values) Option
- func WithFilesystem(fs afero.Fs) Option
- func WithGitignore(text string) Option
- func WithLicense(info *license.Info) Option
- func WithLogger(logger Logger) Option
- func WithOverwriteFiles(paths ...string) Option
- func WithSkipFiles(paths ...string) Option
- type Options
- type Project
- type Source
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithOverwrite ¶
WithOverwrite configures the project to overwrite files present in the target directory. Without this option existing files will not be altered.
Types ¶
type Action ¶
type Action struct {
Type ActionType
Source Source
Destination Destination
}
Action defines an action that should be performed on project creation.
type ActionType ¶
type ActionType uint8
ActionType defines the action that should be performed for a given project file, template or directory.
const ( ActionTypeCreate ActionType = iota ActionTypeOverwrite ActionTypeSkipExisting ActionTypeSkipUser )
type Destination ¶
type Destination struct {
// Base is the base dir of the project.
Base string
// Path is the path relative to the base dir.
Path string
}
Destination describes the destination a project file should be written to.
func (Destination) AbsPath ¶
func (d Destination) AbsPath() string
AbsPath returns the absolute file path of the destination.
func (Destination) Exists ¶
func (d Destination) Exists() bool
Exists returns true if the destination already exists.
func (Destination) RelPath ¶
func (d Destination) RelPath() string
RelPath returns the path relative to the project root.
type Logger ¶
type Logger interface {
// Log produces a log entry for given action.
Log(action Action)
// Stats returns the stats for actions that were passed to Log.
Stats() Stats
// Flush flushes all log entries to the underlying writer.
Flush()
}
Logger logs project actions.
type Option ¶
Option is a func that configures a *Project.
func WithExtraFile ¶
WithExtraFile adds an extra file to the project that is not included in the skeleton the project is created from. The provided io.Reader is used to read the file contents. Path must be relative to the new project root.
func WithExtraValues ¶
WithExtraValues adds additional template values to the project.
func WithFilesystem ¶
WithFilesystem sets the filesystem the project is created on. For example, in tests or during dry run this can be used to perform all operations against an in-memory filesystem instead.
func WithGitignore ¶
WithGitignore adds a .gitignore file to the project with given text.
func WithLicense ¶
WithLicense adds a LICENSE file to the project which is populated from given info. Placeholders for project name and owner are replaced automatically replaced with values from the project config prior to writing the file. The license info is also made available to templates.
func WithLogger ¶
WithLogger configures the logger that is used to output actions performed while creating the project.
func WithOverwriteFiles ¶
WithOverwriteFiles allows for selectively overwriting only a subset of existing file paths. The provided paths must be relative to the project root.
func WithSkipFiles ¶
WithSkipFiles allows for selectively excluding files from the new project. The provided paths must be relative to the project root.
type Project ¶
type Project struct {
// contains filtered or unexported fields
}
Project holds the configuration for a new project that can be created from a *skeleton.Skeleton.
type Source ¶
type Source interface {
// Path must return the path relative to the new project root.
Path() string
// Mode returns the mode of the file. The target in the project directory
// will be created using this mode. The mode is also used to determine if
// the file is regular or a directory.
Mode() os.FileMode
// Reader provides an io.Reader to read the contents of the file.
Reader() (io.Reader, error)
// IsTemplate returns to if the source is a template.
IsTemplate() bool
}
Source is the interface for a source file that should be created in new projects.