interactive

package
v0.0.0-...-2cb4bbe Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Helper functions for running interactive CLI sessions from Go

Helper functions for running interactive CLI sessions from Go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name string
	Args []string
	// If LogFile is set, anything send to stdout and stderr is tee'd to the file named in LogFile when .Run() is called.
	LogFile string
	// contains filtered or unexported fields
}

Command represents running an executable, to make it easy to write interactive "shell scripts" in Go. This routes standard in, out, and error from and to the calling program, intended usually to be a login shell run by a person.

func NewCommand

func NewCommand(cmdAndArgs ...string) Command

NewCommand creates an Command, breaking out .Name and .Args for you

func (*Command) AddArgs

func (c *Command) AddArgs(args ...string)

AddArgs appends arguments to the current list of args

func (Command) Run

func (c Command) Run() error

Run executes the command with exec.Command(), sets standard in/out/err, and returns the result of exec.Cmd.Run() Will tee stdout&err to .LogFile if set

func (Command) String

func (c Command) String() string

String conforms to Stringer

type Docker

type Docker struct {
	Command
}

Docker is mostly an Command preloaded with arguments which setup Docker for running an image interactively.

func NewDocker

func NewDocker() Docker

NewDocker creates a Docker instance with default Docker command arguments for running interactively.

func (*Docker) AddEnv

func (d *Docker) AddEnv(e Env)

AddEnv adds arguments so all the environment variables present in e become part of the docker run's environment

func (*Docker) AddMount

func (d *Docker) AddMount(typeStr, source, target string, optAdditionalArgs ...string)

AddMount add arguments for the --mount command

func (*Docker) AddRWOverlay

func (d *Docker) AddRWOverlay(externalDirectory, internalDirectory string) func()

AddRWOverlay mounts a directory into the image at the desired location, but with an overlay

so internal changes do not modify the external directory.

externalDirectory probably needs to be an absolute path Returns a function to clean up the mount (but does not delete the directory). Uses sudo and probably only works on Linux

type Env

type Env map[string]string

Env represents a collection of environment variables and their values

func (Env) PromoteFromEnv

func (e Env) PromoteFromEnv(envVars ...string) error

PromoteFromEnv pulls the named environment variables from the environment and puts them in the Env. It does not stop on error and returns an error listing all the failed values

Jump to

Keyboard shortcuts

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