env

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(filename string, isSystem bool) (int, error)

func Export

func Export(filename string, envVars []EnvVar) error

func GetSystem

func GetSystem(key string) (string, error)

GetSystem gets a specific system environment variable value.

func GetUser

func GetUser(key string) (string, error)

GetUser gets a specific user environment variable value.

func ParseEnvFile

func ParseEnvFile(content []byte, startWith string) ([]doraemon.Pair[string, string], error)

ParseEnvFile parses environment file content and returns key-value pairs. It supports optional prefix filtering with startWith parameter.

func Restore

func Restore(filename string, isSystem bool) (int, error)

func Set

func Set(key, value string) error

Set sets a user environment variable using setx command.

func SetPS

func SetPS(key, value string) error

SetPS sets a user environment variable using PowerShell. This method handles keys and values containing '&' correctly.

func SetSystem

func SetSystem(key, value string) error

SetSystem sets a system environment variable using setx /m command. Requires administrator privileges.

func Unset

func Unset(key string) error

Unset removes a user environment variable.

func UnsetSystem

func UnsetSystem(key string) error

UnsetSystem removes a system environment variable. Requires administrator privileges.

Types

type BackupData

type BackupData struct {
	CreatedAt time.Time `json:"created_at"`
	Source    string    `json:"source"`
	EnvVars   []EnvVar  `json:"env_vars"`
}

func LoadBackup

func LoadBackup(filename string) (*BackupData, error)

type EnvVar

type EnvVar struct {
	Key   string
	Value string
}

EnvVar represents an environment variable with key and value.

func ListSystem

func ListSystem() ([]EnvVar, error)

ListSystem lists all system environment variables from registry.

func ListUser

func ListUser() ([]EnvVar, error)

ListUser lists all user environment variables from registry.

func SearchSystem

func SearchSystem(keyword string) ([]EnvVar, error)

SearchSystem searches system env vars by keyword (case-insensitive, matches key or value).

func SearchUser

func SearchUser(keyword string) ([]EnvVar, error)

SearchUser searches user env vars by keyword (case-insensitive, matches key or value).

type ExportFormat

type ExportFormat string
const (
	FormatShell ExportFormat = "sh"
	FormatBatch ExportFormat = "bat"
	FormatJSON  ExportFormat = "json"
)

func DetectFormat

func DetectFormat(filename string) ExportFormat

Jump to

Keyboard shortcuts

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