proj

package
v0.8.10 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package proj contains types and functions for managing a project's Earthfile(s).

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("proj: this project is not a supported type")

ErrSkip is an error that means that the project should skip this generator.

Functions

This section is empty.

Types

type Cmd

type Cmd interface {
	// Run is used to run the command. If the command needs to be canceled (or
	// time out), then ctx should be used to do so.
	Run(ctx context.Context) (stdout, stderr io.Reader, _ error)
}

Cmd represents the type that proj types will use to execute commands.

type Execer

type Execer interface {
	Command(name string, args ...string) Cmd
}

Execer represents a type that can return commands that may be executed in the OS.

func StdExecer

func StdExecer() Execer

StdExecer returns a standard library Execer (mostly wrapping the exec package) for use in most use cases of this package.

type FS

type FS interface {
	Open(name string) (fs.File, error)
	Stat(name string) (fs.FileInfo, error)
}

FS represents the type that proj types need to inspect files in the filesystem in order to detect what should be in the generated Earthfile(s).

func StdFS

func StdFS() FS

StdFS returns a standard library FS for use in most use cases of this package.

type Golang

type Golang struct {
	// contains filtered or unexported fields
}

Golang is used to auto-generate Earthfiles for go projects.

func NewGolang

func NewGolang(fs FS, execer Execer) *Golang

NewGolang returns a new Golang.

func (*Golang) ForDir

func (g *Golang) ForDir(ctx context.Context, dir string) (Project, error)

ForDir returns a Project for the given directory. It returns ErrSkip if the directory does not contain a go project.

func (*Golang) Root

func (g *Golang) Root(context.Context) string

Root returns the root path of this Golang project.

func (*Golang) Targets

func (g *Golang) Targets(_ context.Context) ([]Target, error)

Targets returns the targets that should be used for this Golang project.

func (*Golang) Type

func (g *Golang) Type(context.Context) string

Type returns 'go'

type Project

type Project interface {
	// Root returns the root directory for this Project.
	Root(context.Context) string

	// Type returns a unique name for this project type. It will be used for
	// conflict avoidance (i.e. making sure we don't have two go modules loaded)
	// and as a prefix for targets in multi-project-type Earthfiles.
	Type(context.Context) string

	// Targets returns a list of targets for this Project.
	Targets(ctx context.Context) ([]Target, error)
}

Project is a type that can generate Earthfile code for a given project.

func All

func All(ctx context.Context, dir string) ([]Project, error)

All returns all available project types for the given dir.

type ProjectType

type ProjectType interface {
	// ForDir returns a Project for the named directory. It should return
	// ErrSkip if there is no project matching this ProjectType at the requested
	// dir.
	ForDir(ctx context.Context, dir string) (Project, error)
}

ProjectType represents a type of project (typically a language).

type Target

type Target interface {
	// SetPrefix sets a prefix to prepend to this target's name.
	SetPrefix(context.Context, string)

	// Format writes out the target with the given indentation string and level.
	Format(ctx context.Context, w io.Writer, indent string, level int) error
}

Target is a type that can write a formatted target with a given indent string and indentation level

Jump to

Keyboard shortcuts

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