package os

import "codeberg.org/anaseto/goal/os"

Package os provides Goal's default IO/OS builtins.

Use the Import function to register the variadic functions provided by this package.

Various variadic functions automatically work on new goal.BV value types as long as they satisfy the relevant interface:

io.Reader: read
io.Writer: print,say
io.Closer: close
fs.FS: all builtins accepting a file system value left
interface{ Flush() error }: flush
interface{ Stat() (fs.FileInfo, error) }: stat

Index

Functions

func Import

func Import(ctx *goal.Context, pfx string)

Import registers in the given Context all the core Goal IO variadic functions as verbs with default names and valence. It also assigns command-line arguments and standard filehandles to globals.

If the given prefix string is not empty, it is used as a common dot prefix for names. Note, however, that the cmd/goal interpreter and library files in lib/ are designed to work together with an empty prefix.

Monads: abspath chdir close dirfs flush mkdir remove

Dyads: env glob import open print read rename run say shell stat subfs

Globals: ARGS STDIN STDOUT STDERR

Note that subfs comes from the io/fs package, but is registered for convenience by this function.

func NewDirFS

func NewDirFS(dir string) goal.V

NewDirFS returns a Goal value corresponding to dirfs dir.

func NewFileReader

func NewFileReader(f *os.File, buffered bool) goal.V

NewFileReader returns a reader handle for the given file. It may be buffered for non-directory files if enabled. It assumes the file has been opened in read mode.

func NewFileWriter

func NewFileWriter(f *os.File, buffered bool) goal.V

NewFileWriter returns a writer handle for the given file, using buffering if enabled. It assumes the file has been opened in write or append mode.

func NewOSError

func NewOSError(err error) goal.V

NewOSError converts an operating-system Go error to a Goal error dict value with fields as described in the FAQ.

func NewStringReader

func NewStringReader(s string) goal.V

NewStringReader returns a string reader handle Goal value for the given string.

func NewStringWriter

func NewStringWriter(i int) goal.V

NewStringWriter returns a string writer handle Goal value, with initial buffer of size i.

Source Files

env.go handle.go os.go print.go read.go

Version
v1.1.0 (latest)
Published
Feb 17, 2025
Platform
linux/amd64
Imports
16 packages
Last checked
32 minutes ago

Tools for package owners.