fsys

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(dir fs.FS, path string) (bool, error)

Checks if a file exists.

func LookPath

func LookPath(dir ParentFS, files ...string) (string, error)

Like os.LookPath but tries multiple executables left-to-right.

Types

type ParentFS

type ParentFS interface {
	fs.FS

	// Full path for the current dir.
	Path() string

	// Base path for the current dir (similar to path.Base(this.Path()))
	Base() string

	// True unless the current dir is a root dir.
	HasParent() bool

	// Resolves parent dir if HasParent() == true
	Parent() ParentFS

	// Like LookPath from os/exec but local executable paths are
	// interpreted relative to current FS.
	LookPath(string) (string, error)
}

File system and os interface. Helps test executor detection. Extends fs.FS with ability to explore parent folders, search for executables in PATH.

func DirFS

func DirFS(dir string) ParentFS

Use the real OS.

func TestFS

func TestFS(
	workdir string,
	globalPath map[string]string,
	files fstest.MapFS,
) ParentFS

Implements parentFS for testing. Unlike the prod implementation, path operations do not vary by OS but are unix-y.

files is an in-memory filesystem

workdir is a relative path to the current working dir in the in-memory filesystem

globalPath maps short executable names to full paths to emulate PATH resolution in LookPath.

Jump to

Keyboard shortcuts

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