envset

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSection = ini.DEFAULT_SECTION

DefaultSection is the name of the default ini section

Variables

This section is empty.

Functions

func CreateMetadataFile

func CreateMetadataFile(o MetadataOptions) error

CreateMetadataFile will create or update metadata file

func DocumentTemplate

func DocumentTemplate(name, template string, overwrite, print bool) error

DocumentTemplate will create or update a document template e.g. envset.tpl that we use to document and to check in our repo so we can keep track of the variables and sections.

func FileFinder

func FileFinder(filename string) (string, error)

FileFinder will find the file and return its full path

func InterpolateKVStrings

func InterpolateKVStrings(args []string, context EnvMap, expand bool) []string

InterpolateKVStrings replace ${VAR} in the executable cmd arguments

func IsErrorRunningCommand

func IsErrorRunningCommand(v interface{}) bool

ErrorRunningCommand will return true if v is section not found

func IsFileNotFound

func IsFileNotFound(v interface{}) bool

IsFileNotFound will return true if v is file not found

func IsSectionNotFound

func IsSectionNotFound(v interface{}) bool

IsSectionNotFound will return true if v is section not found

func Print

func Print(environment, name string, isolated, expand bool) error

Print will show the current environment We don't need to do variable replacement if we print since the idea is to use it as a source

func Run

func Run(environment string, options RunOptions) error

Run will run the given command after loading the environment

Types

type EnvFile

type EnvFile struct {
	//TODO: make relative to executable
	Path     string    `json:"-"`
	File     *ini.File `json:"-"`
	Filename string    `json:"envfile,omitempty"`
	//TODO: should we have https, git and id? if someone checks using
	//https and other ssh this will change!!
	Project string `json:"project,omitempty"`
	Alg     string `json:"algorithm"`
	//TODO: make custom marshaller to ignore DEFAULT section
	Sections []*EnvSection `json:"sections"`
}

EnvFile struct

func (*EnvFile) AddSection

func (e *EnvFile) AddSection(name string) *EnvSection

AddSection will add a section to a EnvFile

func (*EnvFile) FromJSON

func (e *EnvFile) FromJSON(path string) error

FromJSON load from json file

func (*EnvFile) FromStdin

func (e *EnvFile) FromStdin() error

FromStdin read from stdin

func (*EnvFile) GetSection

func (e *EnvFile) GetSection(name string) (*EnvSection, error)

GetSection will return a EnvSection by name or an error if is not found

func (EnvFile) Load

func (e EnvFile) Load(path string) error

Load will load the ini file

func (EnvFile) ToJSON

func (e EnvFile) ToJSON() (string, error)

ToJSON will print the JSON representation for a envfile

type EnvKey

type EnvKey struct {
	Name    string `json:"key"`
	Value   string `json:"value,omitempty"`
	Hash    string `json:"hash"`
	Comment string `json:"comment,omitempty"`
}

EnvKey is a single entry in our file

type EnvMap

type EnvMap map[string]string

EnvMap type to hold envset map

func LoadIniSection

func LoadIniSection(sec *ini.Section) EnvMap

LoadIniSection returns a new EnvMap from a ini section

func LoadJSON

func LoadJSON(b []byte) (EnvMap, error)

LoadJSON will load a json environment definition

func LocalEnv

func LocalEnv() EnvMap

LocalEnv will return the local env

func NewEnvMap

func NewEnvMap() EnvMap

NewEnvMap returns a new EnvMap

func (EnvMap) Expand

func (e EnvMap) Expand(osExpand bool) error

Expand ${VAR} and $(command) in values

func (EnvMap) GetMissingKeys

func (e EnvMap) GetMissingKeys(keys []string) []string

GetMissingKeys will compare the keys present in `keys` with the keys present in the EnvMap instance and return a list of missing keys.

func (EnvMap) ToExpandedKVStrings

func (e EnvMap) ToExpandedKVStrings(osExpand bool) []string

ToExpandedKVStrings returns an expanded list of key=value strings

func (EnvMap) ToKVStrings

func (e EnvMap) ToKVStrings() []string

ToKVStrings will return an slice of `key=values`

type EnvSection

type EnvSection struct {
	Name    string    `json:"name"`
	Comment string    `json:"comment,omitempty"`
	Keys    []*EnvKey `json:"values"`
}

EnvSection is a top level section

func CompareSections

func CompareSections(s1, s2 EnvSection) EnvSection

CompareSections will compare two sections and return diff

func (*EnvSection) AddKey

func (e *EnvSection) AddKey(key, value, secret string) (*EnvKey, error)

AddKey adds a new key to the section

func (*EnvSection) IsEmpty

func (e *EnvSection) IsEmpty() bool

IsEmpty will return true if we have no keys in our section

type EnvSlice

type EnvSlice []string

EnvSlice type to hold envset entries

func (EnvSlice) Add

func (e EnvSlice) Add(k, v string)

type ErrorRunningCommand

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

func (ErrorRunningCommand) Error

func (e ErrorRunningCommand) Error() string

type MetadataOptions

type MetadataOptions struct {
	Name          string
	Filepath      string
	Algorithm     string
	Project       string
	GlobalSection string
	Overwrite     bool
	Globals       bool
	Print         bool
	Values        bool
	Secret        string
}

MetadataOptions are the command options

type RunOptions added in v0.0.5

type RunOptions struct {
	Filename      string
	Cmd           string
	Args          []string
	Isolated      bool
	Expand        bool
	Required      []string
	ExportEnvName string
}

RunOptions is used to configure a run command

Jump to

Keyboard shortcuts

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