shell

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, runID ulid.ULID, path, content string, allVars []string) error

Run is responsible for assembling an interpreter's execution environment (setting environment variables, working directory, IO/output, etc) and running the command Accepts:

  • context
  • ULID specific to this run
  • path to the script
  • string containing the contents of the templated script
  • a slice of strings in `key=value` pair containing the merged variables to be provided to the script as environment variables

Types

type VariableMap

type VariableMap map[string]string

VariableMap is an alias for `map[string]string`, where the key is the variable name and the string is the variable value

func MakeVariableMap added in v0.2.0

func MakeVariableMap(varSlice VariableSlice) VariableMap

MakeVariableMap is a convenience function to conert a `VariableSlice` to a `VariableMap`

type VariableSlice added in v0.1.0

type VariableSlice []string

VariableSlice is an alias for `[]string`, where each item is an environment variable in `key=value` form, the same as returned by `os.Environ()`

func MergeVariables added in v0.2.0

func MergeVariables(maps ...VariableMap) VariableSlice

func SourceFile

func SourceFile(ctx context.Context, path string) (VariableSlice, error)

SourceFile sources a shell file from disk and returns the variables declared in it. It is a convenience function that uses a default shell parser, parses a file from disk, and calls SourceNode.

This function should be used with caution, as it can interpret arbitrary code. Untrusted shell programs shoudn't be sourced outside of a sandbox environment.

func SourceNode

func SourceNode(ctx context.Context, node syntax.Node) (VariableSlice, error)

SourceNode sources a shell program from a node and returns the variables declared in it. Variables are returned in the same format as `os.Environ()` -- ie, `[]string{"key=value",...}`. It accepts the same set of node types that interp/Runner.Run does.

This function should be used with caution, as it can interpret arbitrary code. Untrusted shell programs shoudn't be sourced outside of a sandbox environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL