ax

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: EUPL-1.2 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(path string) core.Result

Abs resolves a path against the current working directory.

Usage example: abs, err := ax.Abs("./testdata")

Example
_ = Abs(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Abs")
Output:
Abs

func Base

func Base(path string) string

Base returns the last path element.

Usage example: name := ax.Base("/tmp/dist/app.tar.gz")

Example
_ = Base(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Base")
Output:
Base

func Chmod

func Chmod(path string, mode fs.FileMode) core.Result

Chmod updates file permissions without importing os.

Usage example: err := ax.Chmod("dist/app", 0o755)

Example
_ = Chmod(core.Path(core.TempDir(), "go-build-compliance"), 0o755)
core.Println("Chmod")
Output:
Chmod

func Chtimes

func Chtimes(path string, atime, mtime time.Time) core.Result

Chtimes updates access and modification times without importing the OS package.

Usage example: err := ax.Chtimes("dist/app", modTime, modTime)

Example
path := Join(core.TempDir(), "go-build-compliance-chtimes")
_ = WriteString(path, "agent", 0o644)
_ = Chtimes(path, time.Unix(123, 0), time.Unix(123, 0))
core.Println("Chtimes")
Output:
Chtimes

func Clean

func Clean(path string) string

Clean normalises a filesystem path using Core path primitives.

Usage example: clean := ax.Clean("./dist/../dist/output")

Example
_ = Clean(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Clean")
Output:
Clean

func CombinedOutput

func CombinedOutput(ctx context.Context, dir string, env []string, command string, args ...string) core.Result

CombinedOutput executes a command and returns combined output.

Usage example: output, err := ax.CombinedOutput(ctx, repoDir, nil, "go", "test", "./...")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = CombinedOutput(ctx, core.Path(core.TempDir(), "go-build-compliance"), []string{"agent"}, "dappcore-command-not-found")
core.Println("CombinedOutput")
Output:
CombinedOutput

func Create

func Create(path string) core.Result

Create opens a file for writing via io.Local.

Usage example: file, err := ax.Create("dist/output.txt")

Example
_ = Create(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Create")
Output:
Create

func DS

func DS() string

DS returns the current platform directory separator.

Usage example: read ax.DS() when building Core-aware filesystem paths.

Example

--- v0.9.0 generated usage examples ---

_ = DS()
core.Println("DS")
Output:
DS

func Dir

func Dir(path string) string

Dir returns the parent directory for a path.

Usage example: dir := ax.Dir("/tmp/dist/app.tar.gz")

Example
_ = Dir(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Dir")
Output:
Dir

func Exec

func Exec(ctx context.Context, command string, args ...string) core.Result

Exec executes a command without capturing output.

Usage example: err := ax.Exec(ctx, "go", "test", "./...")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = Exec(ctx, "dappcore-command-not-found")
core.Println("Exec")
Output:
Exec

func ExecDir

func ExecDir(ctx context.Context, dir, command string, args ...string) core.Result

ExecDir executes a command in a specific directory without capturing output.

Usage example: err := ax.ExecDir(ctx, repoDir, "go", "test", "./...")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = ExecDir(ctx, core.Path(core.TempDir(), "go-build-compliance"), "dappcore-command-not-found")
core.Println("ExecDir")
Output:
ExecDir

func ExecWithEnv

func ExecWithEnv(ctx context.Context, dir string, env []string, command string, args ...string) core.Result

ExecWithEnv executes a command with additional environment variables.

Usage example: err := ax.ExecWithEnv(ctx, repoDir, []string{"GOOS=linux"}, "go", "build")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = ExecWithEnv(ctx, core.Path(core.TempDir(), "go-build-compliance"), []string{"agent"}, "dappcore-command-not-found")
core.Println("ExecWithEnv")
Output:
ExecWithEnv

func ExecWithWriters

func ExecWithWriters(ctx context.Context, dir string, env []string, stdout, stderr io.Writer, command string, args ...string) core.Result

ExecWithWriters executes a command and streams output to the provided writers.

Usage example: err := ax.ExecWithWriters(ctx, repoDir, nil, w, w, "docker", "build", ".")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = ExecWithWriters(ctx, core.Path(core.TempDir(), "go-build-compliance"), []string{"agent"}, core.NewBuffer(), core.NewBuffer(), "dappcore-command-not-found")
core.Println("ExecWithWriters")
Output:
ExecWithWriters

func Exists

func Exists(path string) bool

Exists reports whether a path exists.

Usage example: if ax.Exists("dist") { ... }

Example
_ = Exists(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Exists")
Output:
Exists

func Ext

func Ext(path string) string

Ext returns the filename extension including the dot.

Usage example: ext := ax.Ext("app.tar.gz")

Example
_ = Ext(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Ext")
Output:
Ext

func FromSlash

func FromSlash(path string) string

FromSlash rewrites slash-separated paths for the current platform.

Usage example: path := ax.FromSlash("ui/dist/index.html")

Example
_ = FromSlash(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("FromSlash")
Output:
FromSlash

func Geteuid

func Geteuid() int

Geteuid returns the effective UID.

Usage example: if ax.Geteuid() == 0 { ... }

Example
_ = Geteuid()
core.Println("Geteuid")
Output:
Geteuid

func Getgid

func Getgid() int

Getgid returns the current process GID.

Usage example: gid := ax.Getgid()

Example
_ = Getgid()
core.Println("Getgid")
Output:
Getgid

func Getuid

func Getuid() int

Getuid returns the current process UID.

Usage example: uid := ax.Getuid()

Example
_ = Getuid()
core.Println("Getuid")
Output:
Getuid

func Getwd

func Getwd() core.Result

Getwd returns the current working directory from Core environment metadata.

Usage example: cwd, err := ax.Getwd()

Example
_ = Getwd()
core.Println("Getwd")
Output:
Getwd

func IsAbs

func IsAbs(path string) bool

IsAbs reports whether a path is absolute.

Usage example: if ax.IsAbs(outputDir) { ... }

Example
_ = IsAbs(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("IsAbs")
Output:
IsAbs

func IsDir

func IsDir(path string) bool

IsDir reports whether a path is a directory.

Usage example: if ax.IsDir(".core") { ... }

Example
_ = IsDir(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("IsDir")
Output:
IsDir

func IsFile

func IsFile(path string) bool

IsFile reports whether a path is a regular file.

Usage example: if ax.IsFile("go.mod") { ... }

Example
_ = IsFile(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("IsFile")
Output:
IsFile

func JSONMarshal

func JSONMarshal(value any) core.Result

JSONMarshal returns a JSON string using Core's JSON wrapper.

Usage example: data, err := ax.JSONMarshal(cfg)

Example
_ = JSONMarshal("agent")
core.Println("JSONMarshal")
Output:
JSONMarshal

func JSONUnmarshal

func JSONUnmarshal(data []byte, target any) core.Result

JSONUnmarshal decodes JSON into target using Core's JSON wrapper.

Usage example: err := ax.JSONUnmarshal(data, &cfg)

Example
_ = JSONUnmarshal([]byte("agent"), "agent")
core.Println("JSONUnmarshal")
Output:
JSONUnmarshal

func Join

func Join(parts ...string) string

Join combines path segments without relying on path/filepath.

Usage example: path := ax.Join(projectDir, ".core", "build.yaml")

Example
_ = Join()
core.Println("Join")
Output:
Join

func LookPath

func LookPath(name string) core.Result

LookPath resolves a program on PATH via the Core process package.

Usage example: path, err := ax.LookPath("git")

Example
_ = LookPath("agent")
core.Println("LookPath")
Output:
LookPath

func Mkdir

func Mkdir(path string, mode fs.FileMode) core.Result

Mkdir ensures a directory exists.

Usage example: err := ax.Mkdir(".core", 0o755)

Example
_ = Mkdir(core.Path(core.TempDir(), "go-build-compliance"), 0o755)
core.Println("Mkdir")
Output:
Mkdir

func MkdirAll

func MkdirAll(path string, _ fs.FileMode) core.Result

MkdirAll ensures a directory exists.

Usage example: err := ax.MkdirAll("dist/linux_arm64", 0o755)

Example
_ = MkdirAll(core.Path(core.TempDir(), "go-build-compliance"), 0o755)
core.Println("MkdirAll")
Output:
MkdirAll

func MkdirTemp

func MkdirTemp(prefix string) core.Result

MkdirTemp creates a temporary directory via Core's filesystem primitive.

Usage example: dir, err := ax.MkdirTemp("core-build-*")

Example
_ = MkdirTemp("agent")
core.Println("MkdirTemp")
Output:
MkdirTemp

func Open

func Open(path string) core.Result

Open opens a file for reading via io.Local.

Usage example: file, err := ax.Open("README.md")

Example
_ = Open(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Open")
Output:
Open

func ReadDir

func ReadDir(path string) core.Result

ReadDir lists directory entries via io.Local.

Usage example: entries, err := ax.ReadDir("dist")

Example
_ = ReadDir(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("ReadDir")
Output:
ReadDir

func ReadFile

func ReadFile(path string) core.Result

ReadFile reads a file into bytes via io.Local.

Usage example: data, err := ax.ReadFile("go.mod")

Example
_ = ReadFile(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("ReadFile")
Output:
ReadFile
func Readlink(path string) core.Result

Readlink reads a symbolic link target without importing the OS package.

Usage example: target, err := ax.Readlink("dist/current")

func Rel

func Rel(base, target string) core.Result

Rel returns target relative to base when target is inside base.

Usage example: rel, err := ax.Rel(projectDir, artifactPath)

Example
_ = Rel("agent", "linux")
core.Println("Rel")
Output:
Rel

func RemoveAll

func RemoveAll(path string) core.Result

RemoveAll removes a file or directory tree.

Usage example: err := ax.RemoveAll("dist")

Example
_ = RemoveAll(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("RemoveAll")
Output:
RemoveAll

func ResolveCommand

func ResolveCommand(name string, fallbackPaths ...string) core.Result

ResolveCommand resolves a program from PATH or a list of fallback paths.

Usage example: path, err := ax.ResolveCommand("task", "/opt/homebrew/bin/task")

Example
_ = ResolveCommand("agent")
core.Println("ResolveCommand")
Output:
ResolveCommand

func Run

func Run(ctx context.Context, command string, args ...string) core.Result

Run executes a command and returns trimmed combined output.

Usage example: output, err := ax.Run(ctx, "git", "status", "--short")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = Run(ctx, "dappcore-command-not-found")
core.Println("Run")
Output:
Run

func RunDir

func RunDir(ctx context.Context, dir, command string, args ...string) core.Result

RunDir executes a command in the provided directory and returns combined output.

Usage example: output, err := ax.RunDir(ctx, repoDir, "git", "show", "--stat")

Example
ctx, cancel := core.WithCancel(core.Background())
cancel()
_ = RunDir(ctx, core.Path(core.TempDir(), "go-build-compliance"), "dappcore-command-not-found")
core.Println("RunDir")
Output:
RunDir

func Stat

func Stat(path string) core.Result

Stat returns file metadata from io.Local.

Usage example: info, err := ax.Stat("go.mod")

Example
_ = Stat(core.Path(core.TempDir(), "go-build-compliance"))
core.Println("Stat")
Output:
Stat

func TempDir

func TempDir(prefix string) core.Result

TempDir creates a temporary directory via Core's filesystem primitive.

Usage example: dir, err := ax.TempDir("core-build-*")

Example
_ = TempDir("agent")
core.Println("TempDir")
Output:
TempDir

func WriteFile

func WriteFile(path string, data []byte, mode fs.FileMode) core.Result

WriteFile writes bytes via io.Local with an explicit mode.

Usage example: err := ax.WriteFile("README.md", []byte("hi"), 0o644)

Example
_ = WriteFile(core.Path(core.TempDir(), "go-build-compliance"), []byte("agent"), 0o755)
core.Println("WriteFile")
Output:
WriteFile

func WriteString

func WriteString(path, data string, mode fs.FileMode) core.Result

WriteString writes text via io.Local with an explicit mode.

Usage example: err := ax.WriteString("README.md", "hi", 0o644)

Example
_ = WriteString(core.Path(core.TempDir(), "go-build-compliance"), "agent", 0o755)
core.Println("WriteString")
Output:
WriteString

Types

This section is empty.

Jump to

Keyboard shortcuts

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