project

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: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithOverwrite

func WithOverwrite(p *Project) error

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.

func NewLogger

func NewLogger(w io.Writer) Logger

NewLogger creates a new Logger which flushes formatted log entries to w.

type Option

type Option func(*Project) error

Option is a func that configures a *Project.

func WithExtraFile

func WithExtraFile(r io.Reader, path string, mode os.FileMode) Option

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

func WithExtraValues(values template.Values) Option

WithExtraValues adds additional template values to the project.

func WithFilesystem

func WithFilesystem(fs afero.Fs) Option

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

func WithGitignore(text string) Option

WithGitignore adds a .gitignore file to the project with given text.

func WithLicense

func WithLicense(info *license.Info) Option

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

func WithLogger(logger Logger) Option

WithLogger configures the logger that is used to output actions performed while creating the project.

func WithOverwriteFiles

func WithOverwriteFiles(paths ...string) Option

WithOverwriteFiles allows for selectively overwriting only a subset of existing file paths. The provided paths must be relative to the project root.

func WithSkipFiles

func WithSkipFiles(paths ...string) Option

WithSkipFiles allows for selectively excluding files from the new project. The provided paths must be relative to the project root.

type Options

type Options []Option

Options is a collection of project configuration options.

func (*Options) Add

func (o *Options) Add(options ...Option) Options

Add adds options to o and returns a copy if it.

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.

func New

func New(config config.Project, targetDir string, options ...Option) (*Project, error)

New creates a new *Project with given config and targetDir.

func (*Project) CreateFromSkeleton

func (p *Project) CreateFromSkeleton(skeleton *skeleton.Skeleton) error

CreateFromSkeleton creates the project from given 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.

func NewSource

func NewSource(r io.Reader, path string, mode os.FileMode) Source

NewSource creates a new source from given reader, path and mode. The path must be relative to the new project root.

type Stats

type Stats map[ActionType]int

Stats is a map from action type to the number of times the action was performed.

func (Stats) String

func (s Stats) String() string

String implements fmt.Stringer.

Returns a string which contains counts of the actions in s.

Jump to

Keyboard shortcuts

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