envars

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalOps added in v0.15.2

func MarshalOps(ops Ops) ([]byte, error)

MarshalOps to JSON.

Types

type Append

type Append struct {
	Name  string ` json:"n"`
	Value string ` json:"v"`
}

Append ensures an element exists at the end of a colon separated list.

func (*Append) Apply

func (e *Append) Apply(transform *Transform)

func (*Append) Envar

func (e *Append) Envar() string

func (*Append) Revert

func (e *Append) Revert(transform *Transform)

func (*Append) String

func (e *Append) String() string

type Envars

type Envars map[string]string

Envars is a convenience alias

func Parse

func Parse(envars []string) Envars

Parse a KEY=VALUE list of environment variables into an Envars map.

func (Envars) Apply

func (e Envars) Apply(envRoot string, ops Ops) *Transform

Apply ops to these Envars and return the resulting Transform.

Envars are not modified.

func (Envars) Clone

func (e Envars) Clone() Envars

Clone envars.

func (Envars) Revert

func (e Envars) Revert(envRoot string, ops Ops) *Transform

Revert creates a Transform that reverts the application of the provided Ops.

Envars are not modified.

func (Envars) System

func (e Envars) System() []string

System renders the Envars in the format expected by the system, ie. KEY=VALUE

type Force

type Force struct {
	Name  string ` json:"n"`
	Value string ` json:"v"`
}

Force set/unset an environment variable without preserving or restoring its previous value.

func (*Force) Apply

func (f *Force) Apply(transform *Transform)

func (*Force) Envar

func (f *Force) Envar() string

func (*Force) Revert

func (f *Force) Revert(transform *Transform)

func (*Force) String

func (f *Force) String() string

type Op

type Op interface {
	fmt.Stringer
	Envar() string
	// Apply changes to transform.
	//
	// This may also add/remove extra housekeeping variables to support Revert.
	Apply(transform *Transform)
	// Revert the changes made by Apply.
	Revert(transform *Transform)
	// contains filtered or unexported methods
}

Op is an operation on an environment variable.

type Ops

type Ops []Op

Ops to apply to a set of environment variables.

func Infer

func Infer(env []string) Ops

Infer uses simple heuristics to build a sequence of transformations for environment variables.

Currently this consists of detecting prepend/append to :-separated lists, set and unset.

func UnmarshalOps added in v0.15.2

func UnmarshalOps(data []byte) (Ops, error)

UnmarshalOps from JSON.

type Prefix

type Prefix struct {
	Name   string ` json:"n"`
	Prefix string ` json:"p"`
}

Prefix ensures the environment variable has the given prefix.

func (*Prefix) Apply

func (p *Prefix) Apply(transform *Transform)

func (*Prefix) Envar

func (p *Prefix) Envar() string

func (*Prefix) Revert

func (p *Prefix) Revert(transform *Transform)

func (*Prefix) String

func (p *Prefix) String() string

type Prepend

type Prepend struct {
	Name  string ` json:"n"`
	Value string ` json:"v"`
}

Prepend ensures an element exists at the beginning of a colon separated list.

func (*Prepend) Apply

func (e *Prepend) Apply(transform *Transform)

func (*Prepend) Envar

func (e *Prepend) Envar() string

func (*Prepend) Revert

func (e *Prepend) Revert(transform *Transform)

func (*Prepend) String

func (e *Prepend) String() string

type Set

type Set struct {
	Name  string ` json:"n"`
	Value string ` json:"v"`
}

Set an environment variable.

func (*Set) Apply

func (e *Set) Apply(transform *Transform)

func (*Set) Envar

func (e *Set) Envar() string

func (*Set) Revert

func (e *Set) Revert(transform *Transform)

func (*Set) String

func (e *Set) String() string

type Transform

type Transform struct {
	// contains filtered or unexported fields
}

Transform encapsulates low-level transformations on an existing environment.

func (*Transform) Changed

func (t *Transform) Changed(undo bool) Envars

Changed returns the set of changed Envars.

If "undo" is true the returned Envars will include undo state.

func (*Transform) Combined

func (t *Transform) Combined() Envars

Combined returns a copy of the full set of original Envars with Changed applied.

Deleted keys will be removed.

func (*Transform) To

func (t *Transform) To(env Envars)

To applies the Transform to "env" in place.

type Unset

type Unset struct {
	Name string ` json:"n"`
}

Unset an environment variable.

func (*Unset) Apply

func (e *Unset) Apply(transform *Transform)

func (*Unset) Envar

func (e *Unset) Envar() string

func (*Unset) Revert

func (e *Unset) Revert(transform *Transform)

func (*Unset) String

func (e *Unset) String() string

Jump to

Keyboard shortcuts

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