hermeti

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 12 Imported by: 7

README

Hermeti

Hermeti is a go package that acts as a framework for hermetic, testable command line interfaces.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutputNotReadable = pear.Defer("output stream is not readable")

Functions

This section is empty.

Types

type CLI

type CLI[T InitRunner] struct {
	Env Env
	App T
	// contains filtered or unexported fields
}

A CLI is a command line interface. It runs an app against an environment

func NewCLI added in v0.7.0

func NewCLI[T InitRunner](env *Env, app T) *CLI[T]

func NewRealCli

func NewRealCli[T InitRunner](exe T) CLI[T]

func NewTestCli

func NewTestCli[T InitRunner](exe T, binaryName string) CLI[T]

func (CLI[T]) ErrStream

func (cli CLI[T]) ErrStream() (*bytes.Buffer, error)

ErrStream returns an io.Reader representing the stuff you put in StdErr.

This will not work in a real CLI because os.StdOut is not readable

func (*CLI[T]) Invoke added in v0.7.0

func (c *CLI[T]) Invoke(str string)

Invoke a cli by using this string and Run ing

func (CLI[T]) OutStream

func (cli CLI[T]) OutStream() (*bytes.Buffer, error)

OutStream returns an io.Reader representing the stuff you put in StdOut.

This will not work in a real CLI because os.StdOut is not readable

func (CLI[T]) Run

func (cli CLI[T]) Run()

Run runs the Runners Run method, passing in Env. It's simply a convenience function.

type Env

type Env struct {
	InStream io.Reader

	OutStream  io.Writer
	ErrStream  io.Writer
	Filesystem afero.IOFS
	Randomness io.Reader
	Args       []string
	Vars       map[string]string
	Exit       func(int)
	// contains filtered or unexported fields
}

Env is a computing environment.

func RealEnv

func RealEnv() Env

RealEnv creates a real Env for a CLI, using standard OS resources

func TestEnv

func TestEnv() Env

TestEnv creates an Env suitable for testing

func (*Env) CaptureOutput added in v0.7.0

func (env *Env) CaptureOutput() (*bytes.Buffer, error)

func (*Env) Mount

func (env *Env) Mount(dirFs fs.ReadDirFS, at string) error

Mount mounts a subdirectory into an environment. Useful for testing. Probably dangerous otherwise

func (*Env) MountDir added in v0.7.0

func (e *Env) MountDir(filePath string) error

mount a real os.Dir into an abstract xfs.DirFS

func (*Env) PipeIn

func (env *Env) PipeIn(r io.Reader) error

PipeIn pipes a stream into stdIn

func (*Env) PipeInFile

func (env *Env) PipeInFile(fpath string) error

func (*Env) PipeInFiles added in v0.5.2

func (env *Env) PipeInFiles(fPaths ...string) error

PipeInFiles pipes in files to the environment's stdin (InputStream)

func (*Env) Spy added in v0.7.0

func (env *Env) Spy(ch chan string) error

type InitRunner

type InitRunner interface {
	Runner
	Initializer
}

type Initializer

type Initializer interface {
	Init(*Env) error
}

An Initializer initializes itself in preparation of running. It can modify its Env

type PassthroughInit

type PassthroughInit struct{}

PassthroughInit is an Initializer that does nothing

func (PassthroughInit) Init

func (p PassthroughInit) Init(_ *Env) error

type Runner

type Runner interface {
	Run(Env)
}

A Runner takes an Env and runs some code against it. It cannot modify the Env.

Directories

Path Synopsis
cmd
chime command
do command
prime command

Jump to

Keyboard shortcuts

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