Documentation
¶
Index ¶
- Variables
- func Build(c *Config) error
- func Interactive(c *Config, in *Interpreter) error
- func Run(c *Config) error
- type Config
- type Interpreter
- func (in *Interpreter) Config()
- func (in *Interpreter) Eval(code string) (v reflect.Value, hasPrint bool, err error)
- func (in *Interpreter) ImportGoal()
- func (in *Interpreter) Interactive() error
- func (in *Interpreter) MonitorSignals()
- func (in *Interpreter) OpenHistory(rl *readline.Instance) error
- func (in *Interpreter) Prompt() string
- func (in *Interpreter) RunCode() (reflect.Value, error)
- func (in *Interpreter) RunConfig() error
- func (in *Interpreter) SaveHistory() error
Constants ¶
This section is empty.
Variables ¶
var Symbols = map[string]map[string]reflect.Value{}
Functions ¶
func Build ¶
Build builds the specified input goal file, or all .goal files in the current directory if no input is specified, to corresponding .go file name(s). If the file does not already contain a "package" specification, then "package main; func main()..." wrappers are added, which allows the same code to be used in interactive and Go compiled modes. go build is run after this.
func Interactive ¶
func Interactive(c *Config, in *Interpreter) error
Interactive runs an interactive shell that allows the user to input goal.
Types ¶
type Config ¶
type Config struct {
// Input is the input file to run/compile.
// If this is provided as the first argument,
// then the program will exit after running,
// unless the Interactive mode is flagged.
Input string `posarg:"0" required:"-"`
// Expr is an optional expression to evaluate, which can be used
// in addition to the Input file to run, to execute commands
// defined within that file for example, or as a command to run
// prior to starting interactive mode if no Input is specified.
Expr string `flag:"e,expr"`
// Dir is a directory path to change to prior to running.
Dir string
// Args is an optional list of arguments to pass in the run command.
// These arguments will be turned into an "args" local variable in the goal.
// These are automatically processed from any leftover arguments passed, so
// you should not need to specify this flag manually.
Args []string `cmd:"run" posarg:"leftover" required:"-"`
// Interactive runs the interactive command line after processing any input file.
// Interactive mode is the default mode for the run command unless an input file
// is specified.
Interactive bool `cmd:"run" flag:"i,interactive"`
// InteractiveFunc is the function to run in interactive mode.
// set it to your own function as needed.
InteractiveFunc func(c *Config, in *Interpreter) error
}
Config is the configuration information for the goal cli.
type Interpreter ¶
type Interpreter struct {
// the goal shell
Goal *goal.Goal
// HistFile is the name of the history file to open / save.
// Defaults to ~/.goal-history for the default goal shell.
// Update this prior to running Config() to take effect.
HistFile string
// the yaegi interpreter
Interp *interp.Interpreter
}
Interpreter represents one running shell context
func NewInterpreter ¶
func NewInterpreter(options interp.Options) *Interpreter
NewInterpreter returns a new Interpreter initialized with the given options. It automatically imports the standard library and configures necessary shell functions. End user app must call [Interp.Config] after importing any additional symbols, prior to running the interpreter.
func (*Interpreter) Config ¶
func (in *Interpreter) Config()
Config performs final configuration after all the imports have been Use'd
func (*Interpreter) Eval ¶
Eval evaluates (interprets) the given code, returning the value returned from the interpreter. HasPrint indicates whether the last line of code has the string print in it, which is for determining whether to print the result in interactive mode. It automatically logs any error in addition to returning it.
func (*Interpreter) ImportGoal ¶
func (in *Interpreter) ImportGoal()
ImportGoal makes the methods of goal object available in goalrun package.
func (*Interpreter) Interactive ¶
func (in *Interpreter) Interactive() error
Interactive runs an interactive shell that allows the user to input goal. Must have done in.Config() prior to calling.
func (*Interpreter) MonitorSignals ¶
func (in *Interpreter) MonitorSignals()
MonitorSignals monitors the operating system signals to appropriately stop the interpreter and prevent the shell from closing on Control+C. It is called automatically in another goroutine in NewInterpreter.
func (*Interpreter) OpenHistory ¶
func (in *Interpreter) OpenHistory(rl *readline.Instance) error
OpenHistory opens history from the current HistFile and loads it into the readline history for given rl instance
func (*Interpreter) Prompt ¶
func (in *Interpreter) Prompt() string
Prompt returns the appropriate REPL prompt to show the user.
func (*Interpreter) RunCode ¶
func (in *Interpreter) RunCode() (reflect.Value, error)
RunCode runs the accumulated set of code lines and clears the stack of code lines. It automatically logs any error in addition to returning it.
func (*Interpreter) RunConfig ¶
func (in *Interpreter) RunConfig() error
RunConfig runs the .goal startup config file in the user's home directory if it exists.
func (*Interpreter) SaveHistory ¶
func (in *Interpreter) SaveHistory() error
SaveHistory saves last 500 (or HISTFILESIZE env value) lines of history, to the current HistFile.