run

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoColor = os.Getenv("NO_COLOR") != "" || os.Getenv("TERM") == "dumb" ||
	(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))

Functions

func Dir

func Dir(dst string, sources ...string) (bool, error)

Dir reports whether any of the sources have been modified more recently than the destination. If a source or destination is a directory, this function returns true if a source has any file that has been modified more recently than the most recently modified file in dst. If the destination file doesn't exist, it always returns true and nil. It's an error if any of the sources don't exist.

func DirNewer

func DirNewer(target time.Time, sources ...string) (bool, error)

DirNewer reports whether any item in sources is newer than the target time. Sources are searched recursively and searching stops as soon as any entry is newer than the target.

func Glob

func Glob(dst string, globs ...string) (bool, error)

Glob expands each of the globs (file patterns) into individual sources and then calls Path on the result, reporting if any of the resulting sources have been modified more recently than the destination. Syntax for Glob patterns is the same as stdlib's filepath.Glob. Note that Glob does not expand environment variables before globbing -- env var expansion happens during the call to Path. It is an error for any glob to return an empty result.

func GlobNewer

func GlobNewer(target time.Time, sources ...string) (bool, error)

GlobNewer performs glob expansion on each source and passes the results to PathNewer for inspection. It returns the first time PathNewer encounters a newer file.

func Must

func Must(err error)

Must panics when err is not nil.

func Must1

func Must1(_ any, err error)

Must1 panics when err is not nil and support an additional parameter.

func Must2

func Must2(_, _ any, err error)

Must2 panics when err is not nil and support two additional parameters.

func Must3

func Must3(_, _, _ any, err error)

Must3 panics when err is not nil and support tree additional parameters.

func Must4

func Must4(_, _, _, _ any, err error)

Must4 panics when err is not nil and support four additional parameters.

func NewestModTime

func NewestModTime(targets ...string) (time.Time, error)

NewestModTime recurses a list of target filesystem objects and finds newest ModTime among them.

func OldestModTime

func OldestModTime(targets ...string) (time.Time, error)

OldestModTime recurses a list of target filesystem objects and finds the oldest ModTime among them.

func Path

func Path(dst string, sources ...string) (bool, error)

Path first expands environment variables like $FOO or ${FOO}, and then reports if any of the sources have been modified more recently than the destination. Path does not descend into directories, it literally just checks the modtime of each thing you pass to it. If the destination file doesn't exist, it always returns true and nil. It's an error if any of the sources don't exist.

func PathNewer

func PathNewer(target time.Time, sources ...string) (bool, error)

PathNewer checks whether any of the sources are newer than the target time. It stops at the first newer file it encounters. Each source path is passed through os.ExpandEnv.

Types

type Dependency

type Dependency interface {
	DependencyIDer
	// Executes the dependency.
	Run(ctx context.Context) error
}

Represents a dependency.

func Fn

func Fn[T fn](fn T) Dependency

Wraps a function with no parameters for the dependency handler.

func Fn1

func Fn1[T fn1[A], A any](fn T, a1 A) Dependency

Wraps a function with one parameter for the dependency handler.

func Fn1WithName

func Fn1WithName[T fn1[A], A any](name string, fn T, a1 A) Dependency

Wraps a function with one parameter and a specific name for the dependency handler.

func Fn2

func Fn2[T fn2[A, B], A, B any](fn T, a1 A, a2 B) Dependency

Wraps a function with two parameters for the dependency handler.

func Fn2WithName

func Fn2WithName[T fn2[A, B], A, B any](name string, fn T, a1 A, a2 B) Dependency

Wraps a function with two parameters and a specific name for the dependency handler.

func Fn3

func Fn3[T fn3[A, B, C], A, B, C any](fn T, a1 A, a2 B, a3 C) Dependency

Wraps a function with three parameters for the dependency handler.

func Fn3WithName

func Fn3WithName[T fn3[A, B, C], A, B, C any](name string, fn T, a1 A, a2 B, a3 C) Dependency

Wraps a function with three parameters and a specific name for the dependency handler.

func Fn4

func Fn4[T fn4[A, B, C, D], A, B, C, D any](fn T, a1 A, a2 B, a3 C, a4 D) Dependency

Wraps a function with four parameters for the dependency handler.

func Fn4WithName

func Fn4WithName[T fn4[A, B, C, D], A, B, C, D any](name string, fn T, a1 A, a2 B, a3 C, a4 D) Dependency

Wraps a function with four parameters and a specific name for the dependency handler.

func Fn5

func Fn5[T fn5[A, B, C, D, E], A, B, C, D, E any](fn T, a1 A, a2 B, a3 C, a4 D, a5 E) Dependency

Wraps a function with five parameters for the dependency handler.

func Fn5WithName

func Fn5WithName[T fn5[A, B, C, D, E], A, B, C, D, E any](name string, fn T, a1 A, a2 B, a3 C, a4 D, a5 E) Dependency

Wraps a function with five parameters and a specific name for the dependency handler.

func Fn6

func Fn6[T fn6[A, B, C, D, E, F], A, B, C, D, E, F any](fn T, a1 A, a2 B, a3 C, a4 D, a5 E, a6 F) Dependency

Wraps a function with six parameters for the dependency handler.

func Fn6WithName

func Fn6WithName[T fn6[A, B, C, D, E, F], A, B, C, D, E, F any](
	name string, fn T, a1 A, a2 B, a3 C, a4 D, a5 E, a6 F,
) Dependency

Wraps a function with six parameters and a specific name for the dependency handler.

func FnWithName

func FnWithName[T fn](name string, fn T) Dependency

Wraps a function with no parameters and a specific name for the dependency handler.

func Meth

func Meth[T fn](s any, fn T) Dependency

Wraps a struct method with no parameters for the dependency handler.

func Meth1

func Meth1[T fn1[A], A any](s any, fn T, a1 A) Dependency

Wraps a struct method with one parameters for the dependency handler.

func Meth2

func Meth2[T fn2[A, B], A, B any](s any, fn T, a1 A, a2 B) Dependency

Wraps a struct method with two parameters for the dependency handler.

func Meth3

func Meth3[T fn3[A, B, C], A, B, C any](s any, fn T, a1 A, a2 B, a3 C) Dependency

Wraps a struct method with three parameters for the dependency handler.

func Meth4

func Meth4[T fn4[A, B, C, D], A, B, C, D any](s any, fn T, a1 A, a2 B, a3 C, a4 D) Dependency

Wraps a struct method with four parameters for the dependency handler.

func Meth5

func Meth5[T fn5[A, B, C, D, E], A, B, C, D, E any](s any, fn T, a1 A, a2 B, a3 C, a4 D, a5 E) Dependency

Wraps a struct method with five parameters for the dependency handler.

func Meth6

func Meth6[T fn6[A, B, C, D, E, F], A, B, C, D, E, F any](s any, fn T, a1 A, a2 B, a3 C, a4 D, a5 E, a6 F) Dependency

Wraps a struct method with six parameters for the dependency handler.

type DependencyID

type DependencyID string

Uses a string as dependency identifier.

func (DependencyID) ID

func (id DependencyID) ID() string

type DependencyIDer

type DependencyIDer interface {
	// Unique Identifier to ensure this dependency only executes once.
	ID() string
}

A depdencency that can uniquely identify itself.

type Manager

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

Manager coordinates runnable targets and dependencies.

func New

func New(opts ...ManagerOption) *Manager

Creates a new Manager.

func (*Manager) Call

func (m *Manager) Call(ctx context.Context, id string, args []string) (err error)

func (*Manager) MustRegisterAndRun

func (m *Manager) MustRegisterAndRun(ctx context.Context, targetGroups ...any)

func (*Manager) ParallelDeps

func (m *Manager) ParallelDeps(ctx context.Context, parent DependencyIDer, deps ...Dependency) error

Executes dependencies in parallel.

func (*Manager) Register

func (m *Manager) Register(targetGroup ...any) error

func (*Manager) RegisterAndRun

func (m *Manager) RegisterAndRun(ctx context.Context, targetGroups ...any) error

func (*Manager) RegisterGoTool

func (m *Manager) RegisterGoTool(tool, packageURL, version string) error

Register a go tool to be installed. The manager ensures that the tool is go install'ed project local and available in $PATH.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

func (*Manager) SerialDeps

func (m *Manager) SerialDeps(ctx context.Context, parent DependencyIDer, deps ...Dependency) error

Executes dependencies one after the other.

type ManagerOption

type ManagerOption interface {
	ApplyToManager(m *Manager)
}

type MustError

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

MustError wraps errors from MustX() functions.

func (*MustError) Error

func (e *MustError) Error() string

type UnknownTargetError

type UnknownTargetError struct {
	ID string
}

UnknownTargetError is raised with no target under the given name could be found.

func (*UnknownTargetError) Error

func (t *UnknownTargetError) Error() string

type WithLogger

type WithLogger struct{ *slog.Logger }

Provide a custom logger to the Manager.

func (WithLogger) ApplyToManager

func (l WithLogger) ApplyToManager(m *Manager)

type WithParallelDeps

type WithParallelDeps []Dependency

Add dependencies that will be run in parallel. Parallel dependencies are run before Serial dependencies.

func (WithParallelDeps) ApplyToManager

func (pd WithParallelDeps) ApplyToManager(m *Manager)

type WithSerialDeps

type WithSerialDeps []Dependency

Add dependencies that will be run in series. Serial dependencies run after Parallel dependencies.

func (WithSerialDeps) ApplyToManager

func (pd WithSerialDeps) ApplyToManager(m *Manager)

type WithSources

type WithSources embed.FS

Source code to use for Help generation. Allows the automatic detection of method comments. Example go-embed directive: //go:embed *.go var source embed.FS.

func (WithSources) ApplyToManager

func (s WithSources) ApplyToManager(m *Manager)

type WithStderr

type WithStderr struct{ io.Writer }

func (WithStderr) ApplyToManager

func (stderr WithStderr) ApplyToManager(m *Manager)

type WithStdout

type WithStdout struct{ io.Writer }

func (WithStdout) ApplyToManager

func (stdout WithStdout) ApplyToManager(m *Manager)

Jump to

Keyboard shortcuts

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