Documentation
¶
Overview ¶
Package shell is the interactive console behind `tango shell`: a Go interpreter booted with a project's configuration, database and model registry, without serving HTTP.
A project's shell/main.go calls Run; nothing else here is public. Importing this package links the Yaegi interpreter, so a server's main package should not import it. The shell executes local developer code with the project's credentials: it is not a sandbox and not a remote administration surface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, config tango.Config, store *db.Store, args []string, opts Options) int
Run boots config's registry against store without serving HTTP, then runs a shell session for args (os.Args[1:] of a project's shell/main.go) and returns the process exit code.
The accepted arguments are -c EXPR (evaluate EXPR and exit), --readonly and --help. With no -c, the session reads standard input. Exit codes: 0 for a session that ended cleanly or --help, 1 for the first error of a non-interactive session or a project that fails to boot, 2 for a command line that is not understood, and 130 when Ctrl-C interrupts an evaluation.
Types ¶
type Options ¶
type Options struct {
// ReadOnly makes every built-in helper that writes fail. The --readonly
// flag has the same effect; either one turns it on.
ReadOnly bool
// Helpers are the project's own functions and values, reachable from
// the session only as project.Name, never by a bare name. Each name must
// be an exported Go identifier; Run refuses to start otherwise. A helper
// closes over what it needs (the store, application services, a
// context) in the project's shell/main.go: the shell passes nothing to
// it. Only plain values (primitives, maps, slices and error) are
// supported across the boundary; a value of a project type arrives, but
// using its fields or methods from the session is not supported.
Helpers map[string]any
// DatabaseLabel is shown at startup so a person can see which database
// the session works on. It is display-only text that the project
// derives from its database configuration after removing every part of
// it that could be a credential (user name, password, URL userinfo). It
// is never a DSN or any other connection value.
DatabaseLabel string
}
Options configures a shell session beyond its command line.