env

package
v0.0.0-...-15f74bb Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package env implements a case-insensitive shell environment with DOS-style variable expansion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

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

Env holds shell environment variables with case-insensitive keys.

func New

func New() *Env

New returns an empty Env.

func (*Env) All

func (e *Env) All() map[string]string

All returns a copy of all variables as a map (keys uppercase).

func (*Env) Args

func (e *Env) Args() []string

Args returns the current batch parameter vector.

func (*Env) Delete

func (e *Env) Delete(key string)

Delete removes a variable.

func (*Env) Expand

func (e *Env) Expand(s string) string

Expand replaces %VAR% and %0..%9 references in s. Unknown variables expand to empty string. %% becomes %. A lone % with no closing % is left as-is.

func (*Env) ExpandDelayed

func (e *Env) ExpandDelayed(s string) string

ExpandDelayed replaces !VAR! references with their current values. A lone ! with no closing ! is passed through unchanged. This is a no-op when delayed expansion is not enabled - callers are responsible for checking the flag before calling.

func (*Env) Get

func (e *Env) Get(key string) string

Get returns the value of the named variable (case-insensitive).

func (*Env) ImportHost

func (e *Env) ImportHost(keys []string)

ImportHost copies named variables from the host environment into e.

func (*Env) Restore

func (e *Env) Restore(snapshot map[string]string)

Restore replaces the entire variable map with the provided snapshot. The args vector is left unchanged.

func (*Env) Set

func (e *Env) Set(key, val string)

Set stores a variable (key is normalized to uppercase).

func (*Env) SetArgs

func (e *Env) SetArgs(args []string)

SetArgs sets the batch parameter vector (%0..%9).

func (*Env) Snapshot

func (e *Env) Snapshot() []string

Snapshot returns all variables as "KEY=value" strings suitable for passing to exec.Cmd.Env.

Jump to

Keyboard shortcuts

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