Documentation
¶
Overview ¶
Package goal provides the Goal Go augmented language transpiler, which combines the best parts of Go, bash, and Python to provide an integrated shell and numerical expression processing experience.
Index ¶
- func AddHomeExpand(list []string, adds ...string) []string
- type Goal
- func (gl *Goal) ActiveSSH() *sshclient.Client
- func (gl *Goal) AddCommand(name string, cmd func(args ...string))
- func (gl *Goal) AddError(err error) error
- func (gl *Goal) AddHistory(line string)
- func (gl *Goal) AddPath(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Args() []any
- func (gl *Goal) CancelExecution()
- func (gl *Goal) Cd(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Close()
- func (gl *Goal) CloseSSH()
- func (gl *Goal) CmdArgs(errOk bool, sargs []string, i int) []string
- func (gl *Goal) CompleteEdit(data any, text string, cursorPos int, completion complete.Completion, ...) (ed complete.Edit)
- func (gl *Goal) CompleteMatch(data any, text string, posLine, posChar int) (md complete.Matches)
- func (gl *Goal) Debug(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) DeleteAllJobs()
- func (gl *Goal) DeleteJob(job *Job) bool
- func (gl *Goal) EndContext()
- func (gl *Goal) Exec(errOk, start, output bool, cmd any, args ...any) string
- func (gl *Goal) ExecArgs(cmdIO *exec.CmdIO, errOk bool, cmd any, args ...any) (*sshclient.Client, string, []string)
- func (gl *Goal) Exit(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Fg(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) GoSSH(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) HandleArgErr(errok bool, err error) error
- func (gl *Goal) History(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Host() string
- func (gl *Goal) HostAndDir() string
- func (gl *Goal) InstallBuiltins()
- func (gl *Goal) JobIDExpand(args []string) int
- func (gl *Goal) JobsCmd(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Kill(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) OpenHistory(file string) error
- func (gl *Goal) OutToFile(cl *sshclient.Client, cmdIO *exec.CmdIO, errOk bool, sargs []string, i int) []string
- func (gl *Goal) OutToPipe(cl *sshclient.Client, cmdIO *exec.CmdIO, errOk bool, sargs []string, i int) []string
- func (gl *Goal) Output(cmd any, args ...any) string
- func (gl *Goal) OutputErrOK(cmd any, args ...any) string
- func (gl *Goal) RestoreOrigStdIO()
- func (gl *Goal) Run(cmd any, args ...any)
- func (gl *Goal) RunBuiltinOrCommand(cmdIO *exec.CmdIO, errOk, start, output bool, cmd string, args ...string) (bool, string)
- func (gl *Goal) RunCommands(cmds []any) error
- func (gl *Goal) RunErrOK(cmd any, args ...any)
- func (gl *Goal) SSHByHost(host string) (*sshclient.Client, error)
- func (gl *Goal) SaveHistory(n int, file string) error
- func (gl *Goal) SaveOrigStdIO()
- func (gl *Goal) Scp(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Set(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Source(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Start(cmd any, args ...any)
- func (gl *Goal) StartContext() context.Context
- func (gl *Goal) TranspileCode(code string)
- func (gl *Goal) TranspileCodeFromFile(file string) error
- func (gl *Goal) TranspileConfig() error
- func (gl *Goal) TranspileFile(in string, out string) error
- func (gl *Goal) Unset(cmdIO *exec.CmdIO, args ...string) error
- func (gl *Goal) Which(cmdIO *exec.CmdIO, args ...string) error
- type Job
- type ReadlineCompleter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHomeExpand ¶
AddHomeExpand adds given strings to the given list of strings, expanding any ~ symbols with the home directory, and returns the updated list.
Types ¶
type Goal ¶
type Goal struct {
// Config is the [exec.Config] used to run commands.
Config exec.Config
// StdIOWrappers are IO wrappers sent to the interpreter, so we can
// control the IO streams used within the interpreter.
// Call SetWrappers on this with another StdIO object to update settings.
StdIOWrappers exec.StdIO
// ssh connection, configuration
SSH *sshclient.Config
// collection of ssh clients
SSHClients map[string]*sshclient.Client
// SSHActive is the name of the active SSH client
SSHActive string
// Builtins are all the builtin shell commands
Builtins map[string]func(cmdIO *exec.CmdIO, args ...string) error
// commands that have been defined, which can be run in Exec mode.
Commands map[string]func(args ...string)
// Jobs is a stack of commands running in the background
// (via Start instead of Run)
Jobs stack.Stack[*Job]
// Cancel, while the interpreter is running, can be called
// to stop the code interpreting.
// It is connected to the Ctx context, by StartContext()
// Both can be nil.
Cancel func()
// Errors is a stack of runtime errors.
Errors []error
// CliArgs are input arguments from the command line.
CliArgs []any
// Ctx is the context used for cancelling current shell running
// a single chunk of code, typically from the interpreter.
// We are not able to pass the context around so it is set here,
// in the StartContext function. Clear when done with ClearContext.
Ctx context.Context
// original standard IO setings, to restore
OrigStdIO exec.StdIO
// Hist is the accumulated list of command-line input,
// which is displayed with the history builtin command,
// and saved / restored from ~/.goalhist file
Hist []string
// transpiling state
TrState transpile.State
// contains filtered or unexported fields
}
Goal represents one running Goal language context.
func (*Goal) AddCommand ¶
AddCommand adds given command to list of available commands.
func (*Goal) AddError ¶
AddError adds the given error to the error stack if it is non-nil, and calls the Cancel function if set, to stop execution. This is the main way that goal errors are handled. It also prints the error.
func (*Goal) AddHistory ¶
AddHistory adds given line to the Hist record of commands
func (*Goal) CancelExecution ¶
func (gl *Goal) CancelExecution()
CancelExecution calls the Cancel() function if set.
func (*Goal) Close ¶
func (gl *Goal) Close()
Close closes any resources associated with the shell, including terminating any commands that are not running "nohup" in the background.
func (*Goal) CompleteEdit ¶
func (gl *Goal) CompleteEdit(data any, text string, cursorPos int, completion complete.Completion, seed string) (ed complete.Edit)
CompleteEdit is the complete.EditFunc for the shell.
func (*Goal) CompleteMatch ¶
CompleteMatch is the complete.MatchFunc for the shell.
func (*Goal) DeleteAllJobs ¶
func (gl *Goal) DeleteAllJobs()
DeleteAllJobs deletes any existing jobs, closing stdio.
func (*Goal) EndContext ¶
func (gl *Goal) EndContext()
EndContext ends a processing context, clearing the Ctx and Cancel fields.
func (*Goal) Exec ¶
Exec handles command execution for all cases, parameterized by the args. It executes the given command string, waiting for the command to finish, handling the given arguments appropriately. If there is any error, it adds it to the goal, and triggers CancelExecution.
- errOk = don't call AddError so execution will not stop on error
- start = calls Start on the command, which then runs asynchronously, with a goroutine forked to Wait for it and close its IO
- output = return the output of the command as a string (otherwise return is "")
func (*Goal) ExecArgs ¶
func (gl *Goal) ExecArgs(cmdIO *exec.CmdIO, errOk bool, cmd any, args ...any) (*sshclient.Client, string, []string)
ExecArgs processes the args to given exec command, handling all of the input / output redirection and file globbing, homedir expansion, etc.
func (*Goal) GoSSH ¶
GoSSH manages SSH connections, which are referenced by the @name identifier. It handles the following cases:
- @name -- switches to using given host for all subsequent commands
- host [name] -- connects to a server specified in first arg and switches to using it, with optional name instead of default sequential number.
- close -- closes all open connections, or the specified one
func (*Goal) Host ¶
Host returns the name we're running commands on, which is empty if localhost (default).
func (*Goal) HostAndDir ¶
HostAndDir returns the name we're running commands on, which is empty if localhost (default), and the current directory on that host.
func (*Goal) InstallBuiltins ¶
func (gl *Goal) InstallBuiltins()
InstallBuiltins adds the builtin goal commands to [Goal.Builtins].
func (*Goal) JobIDExpand ¶
JobIDExpand expands %n job id values in args with the full PID returns number of PIDs expanded
func (*Goal) Kill ¶
Kill kills a job by job number or PID. Just expands the job id expressions %n into PIDs and calls system kill.
func (*Goal) OpenHistory ¶
OpenHistory opens Hist history lines from given file, e.g., ~/.goalhist
func (*Goal) OutToFile ¶
func (gl *Goal) OutToFile(cl *sshclient.Client, cmdIO *exec.CmdIO, errOk bool, sargs []string, i int) []string
OutToFile processes the > arg that sends output to a file
func (*Goal) OutToPipe ¶
func (gl *Goal) OutToPipe(cl *sshclient.Client, cmdIO *exec.CmdIO, errOk bool, sargs []string, i int) []string
OutToPipe processes the | arg that sends output to a pipe
func (*Goal) Output ¶
Output executes the given command string, handling the given arguments appropriately. If there is any error, it adds it to the goal. It returns the stdout as a string and forwards stderr to exec.Config.Stderr appropriately.
func (*Goal) OutputErrOK ¶
OutputErrOK executes the given command string, handling the given arguments appropriately. If there is any error, it adds it to the goal. It returns the stdout as a string and forwards stderr to exec.Config.Stderr appropriately.
func (*Goal) RestoreOrigStdIO ¶
func (gl *Goal) RestoreOrigStdIO()
RestoreOrigStdIO reverts to using the saved OrigStdIO
func (*Goal) Run ¶
Run executes the given command string, waiting for the command to finish, handling the given arguments appropriately. If there is any error, it adds it to the goal, and triggers CancelExecution. It forwards output to exec.Config.Stdout and exec.Config.Stderr appropriately.
func (*Goal) RunBuiltinOrCommand ¶
func (gl *Goal) RunBuiltinOrCommand(cmdIO *exec.CmdIO, errOk, start, output bool, cmd string, args ...string) (bool, string)
RunBuiltinOrCommand runs a builtin or a command, returning true if it ran, and the output string if running in output mode.
func (*Goal) RunCommands ¶
RunCommands runs the given command(s). This is typically called from a Makefile-style goal script.
func (*Goal) RunErrOK ¶
RunErrOK executes the given command string, waiting for the command to finish, handling the given arguments appropriately. It does not stop execution if there is an error. If there is any error, it adds it to the goal. It forwards output to exec.Config.Stdout and exec.Config.Stderr appropriately.
func (*Goal) SSHByHost ¶
SSHByHost returns the SSH client for given host name, with err if not found
func (*Goal) SaveHistory ¶
SaveHistory saves up to the given number of lines of current history to given file, e.g., ~/.goalhist for the default goal program. If n is <= 0 all lines are saved. n is typically 500 by default.
func (*Goal) SaveOrigStdIO ¶
func (gl *Goal) SaveOrigStdIO()
SaveOrigStdIO saves the current Config.StdIO as the original to revert to after an error, and sets the StdIOWrappers to use them.
func (*Goal) Scp ¶
Scp performs file copy over SSH connection, with the remote filename prefixed with the @name: and the local filename un-prefixed. The order is from -> to, as in standard cp. The remote filename is automatically relative to the current working directory on the remote host.
func (*Goal) Start ¶
Start starts the given command string for running in the background, handling the given arguments appropriately. If there is any error, it adds it to the goal. It forwards output to exec.Config.Stdout and exec.Config.Stderr appropriately.
func (*Goal) StartContext ¶
StartContext starts a processing context, setting the Ctx and Cancel Fields. Call EndContext when current operation finishes.
func (*Goal) TranspileCode ¶
TranspileCode processes each line of given code, adding the results to the LineStack
func (*Goal) TranspileCodeFromFile ¶
TranspileCodeFromFile transpiles the code in given file
func (*Goal) TranspileConfig ¶
TranspileConfig transpiles the .goal startup config file in the user's home directory if it exists.
func (*Goal) TranspileFile ¶
TranspileFile transpiles the given input goal file to the given output Go file. If no existing package declaration is found, then package main and func main declarations are added. This also affects how functions are interpreted.
type ReadlineCompleter ¶
type ReadlineCompleter struct {
Goal *Goal
}
ReadlineCompleter implements github.com/cogentcore/readline.AutoCompleter.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
goal
command
Command goal is an interactive cli for running and compiling Goal code.
|
Command goal is an interactive cli for running and compiling Goal code. |
|
Package goalib defines convenient utility functions for use in the goal shell, available with the goalib prefix.
|
Package goalib defines convenient utility functions for use in the goal shell, available with the goalib prefix. |