package cmd

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

Package cmd provides a quick way to create derived interpreters.

Index

Functions

func Exit

func Exit(err error)

Exit causes the current program to exit with status code depending on the given error value. If the error is nil, then code zero is used. Otherwise, the error message is displayed on os.Stderr, and a non-zero code is used. If err is of type *ExitError, status code is read from the Code field, otherwise it defaults to 1.

func Run

func Run(ctx *goal.Context, cfg Config) error

Run runs a goal interpreter with starting context ctx and the given help strings when using the repl. Command line usage is then as follows:

program-name [-d] [-i] [-q] [-version] [-e command | script] [args ...]

The ARGS global variable contains the arguments, starting from script name if given.

Types

type Config

type Config struct {
	Help        func(string) string // defaults to disabling help if nil
	ProgramName string              // defaults to os.Args[0] if empty
	Man         string              // defaults to none if empty
}

Config describes the possible configuration options when running a *goal.Context through Run.

type ExitError

type ExitError struct {
	Msg  string // error message
	Code int    // exit status code
}

ExitError is returned by Run when the program returns a Goal error value. Msg contains the error message. Code is 1 by default. If the error value is a dict value with a code key, following the same convention as the run builtin, then Code is set to the corresponding value (if it is an integer in the [1,125] range).

func (*ExitError) Error

func (e *ExitError) Error() string

Source Files

cmd.go

Directories

PathSynopsis
cmd/goalDefault command-line interpreter for Goal.
cmd/goal2htmlHTML-coloration tool for Goal code based on scan/html.
cmd/wasm
Version
v1.1.0 (latest)
Published
Feb 17, 2025
Platform
linux/amd64
Imports
9 packages
Last checked
41 minutes ago

Tools for package owners.