profilesreader

package
Version: v0.0.0-...-abfb8b1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: BSD-3-Clause Imports: 11 Imported by: 6

Documentation

Overview

Package profilesreader provides support for reading and processing jiri profiles.

Index

Constants

This section is empty.

Variables

View Source
var (
	// A MergePolicy with a Last action.
	UseLast = MergePolicy{Action: Last}
	// A MergePolicy with a First action.
	UseFirst = MergePolicy{Action: First}
	// A MergePolicy that ignores the variable, regardless of where it occurs.
	IgnoreVariable = MergePolicy{Action: Ignore}
	// A MergePolicy that appends using : as a separator.
	AppendPath = MergePolicy{Action: Append, Separator: ":"}
	// A MergePolicy that appends using " " as a separator.
	AppendFlag = MergePolicy{Action: Append, Separator: " "}
	// A MergePolicy that prepends using : as a separator.
	PrependPath = MergePolicy{Action: Prepend, Separator: ":"}
	// A MergePolicy that prepends using " " as a separator.
	PrependFlag = MergePolicy{Action: Prepend, Separator: " "}
	// A MergePolicy that will ignore base, but append across profiles using ':'
	IgnoreBaseAppendPath = MergePolicy{Action: IgnoreBaseAndAppend, Separator: ":"}
	// A MergePolicy that will ignore base, but append across profiles using ' '
	IgnoreBaseAppendFlag = MergePolicy{Action: IgnoreBaseAndAppend, Separator: " "}
	// A MergePolicy that will ignore base, but prepend across profiles using ':'
	IgnoreBasePrependPath = MergePolicy{Action: IgnoreBaseAndPrepend, Separator: ":"}
	// A MergePolicy that will ignore base, but prepend across profiles using ' '
	IgnoreBasePrependFlag = MergePolicy{Action: IgnoreBaseAndPrepend, Separator: " "}
	// A MergePolicy that will ignore base, but use the last value from profiles.
	IgnoreBaseUseFirst = MergePolicy{Action: IgnoreBaseAndUseFirst}
	// A MergePolicy that will ignore base, but use the last value from profiles.
	IgnoreBaseUseLast = MergePolicy{Action: IgnoreBaseAndUseLast}
	// A MergePolicy that will always use the value from base and ignore profiles.
	UseBaseIgnoreProfiles = MergePolicy{Action: IgnoreProfiles}
)
View Source
var GoFlags = []string{
	"CC",
	"CC_FOR_TARGET",
	"CGO_ENABLED",
	"CXX_FOR_TARGET",
	"GO15VENDOREXPERIMENT",
	"GOARCH",
	"GOBIN",
	"GOEXE",
	"GOGCCFLAGS",
	"GOHOSTARCH",
	"GOHOSTOS",
	"GOOS",
	"GOPATH",
	"GORACE",
	"GOROOT",
	"GOTOOLDIR",
}

GoFlags lists all of the Go environment variables and will be sorted in the init function for this package.

Functions

func GoEnvironmentFromOS

func GoEnvironmentFromOS() []string

GoEnvironmentFromOS() returns the values of all Go environment variables as set via the OS; unset variables are omitted.

func MergeEnv

func MergeEnv(policies map[string]MergePolicy, base *envvar.Vars, vars ...[]string)

MergeEnv merges environment variables in base with those in vars according to the suppled policies.

func RegisterReaderFlags

func RegisterReaderFlags(flags *flag.FlagSet, profilesMode *ProfilesMode, manifest, profiles *string, defaultManifest string, policies *MergePolicies)

RegisterReaderFlags registers the flags commonly used with a profiles.Reader. --profiles-manifest, --skip-profiles, --profiles and --merge-policies.

func UnsetGoEnvMap

func UnsetGoEnvMap(env map[string]string)

UnsetGoEnvMap unsets Go environment variables in the given environment.

func UnsetGoEnvVars

func UnsetGoEnvVars(env *envvar.Vars)

UnsetGoEnvVars unsets Go environment variables in the given environment.

func WithDefaultVersion

func WithDefaultVersion(target profiles.Target) profiles.Target

WithDefaultVersion returns a copy of the supplied target with its version set to the default (i.e. emtpy string).

Types

type MergeAction

type MergeAction int
const (
	// Use the first value encountered
	First MergeAction = iota
	// Use the last value encountered.
	Last
	// Ignore the variable regardless of where it occurs.
	Ignore
	// Append the current value to the values already accumulated.
	Append
	// Prepend the current value to the values already accumulated.
	Prepend
	// Ignore the value in the base environment, but append in the profiles.
	IgnoreBaseAndAppend
	// Ignore the value in the base environment, but prepend in the profiles.
	IgnoreBaseAndPrepend
	// Ignore the value in the base environment, but use the first value from profiles.
	IgnoreBaseAndUseFirst
	// Ignore the value in the base environment, but use the last value from profiles.
	IgnoreBaseAndUseLast
	// Ignore the values in the profiles.
	IgnoreProfiles
)

type MergePolicies

type MergePolicies map[string]MergePolicy

func JiriMergePolicies

func JiriMergePolicies() MergePolicies

JiriMergePolicies returns an instance of MergePolicies that contains appropriate default policies for use with MergeEnv from jiri packages and subcommands such as those used to build go, java etc.

func ProfileMergePolicies

func ProfileMergePolicies() MergePolicies

ProfileMergePolicies returns an instance of MergePolicies that containts appropriate default policies for use with MergeEnv from within profile implementations.

func (MergePolicies) DebugString

func (mp MergePolicies) DebugString() string

func (MergePolicies) Get

func (mp MergePolicies) Get() interface{}

Get implements flag.Getter

func (MergePolicies) Set

func (mp MergePolicies) Set(values string) error

Set implements flag.Value

func (MergePolicies) String

func (mp MergePolicies) String() string

String implements flag.Value. It generates a string that can be used to recreate the MergePolicies value and that can be passed as a parameter to another process.

func (MergePolicies) Usage

func (mp MergePolicies) Usage() string

type MergePolicy

type MergePolicy struct {
	Action    MergeAction
	Separator string
}

The environment variables passed to a subprocess are the result of merging those in the processes environment and those from one or more profiles according to the policies defined below. There is a starting environment, nominally called 'base', and one or profile environments. The base environment will typically be that inherited by the running process from its invoking shell. A policy consists of an 'action' and an optional separator to use when concatenating variables.

func (*MergePolicy) String

func (mp *MergePolicy) String() string

type ProfilesMode

type ProfilesMode bool
const (
	UseProfiles  ProfilesMode = false
	SkipProfiles ProfilesMode = true
)

func (*ProfilesMode) Get

func (pm *ProfilesMode) Get() interface{}

func (*ProfilesMode) IsBoolFlag

func (pm *ProfilesMode) IsBoolFlag() bool

func (*ProfilesMode) Set

func (pm *ProfilesMode) Set(s string) error

func (*ProfilesMode) String

func (pm *ProfilesMode) String() string

type Reader

type Reader struct {
	*envvar.Vars
	// contains filtered or unexported fields
}

Reader wraps the various sources of configuration and profile information to provide convenient methods for determing the environment variables to use for a given situation. It creates an initial copy of the OS environment that is mutated by its various methods.

func NewReader

func NewReader(jirix *jiri.X, profilesMode ProfilesMode, path string) (*Reader, error)

NewReader creates a new profiles reader. If path is of non-zero length then that path will be read as a profiles database, if not, the existing, if any, in-memory profiles information will be used. If SkipProfiles is specified for profilesMode, then no profiles are used.

func (*Reader) DebugString

func (rd *Reader) DebugString() string

func (*Reader) EnvFromProfile

func (rd *Reader) EnvFromProfile(name string, target profiles.Target) []string

EnvFromProfile obtains the environment variable settings from the specified profile and target. It returns nil if the target and/or profile could not be found.

func (*Reader) LookupProfile

func (rd *Reader) LookupProfile(name string) *profiles.Profile

func (*Reader) LookupProfileTarget

func (rd *Reader) LookupProfileTarget(name string, target profiles.Target) *profiles.Target

func (*Reader) MergeEnv

func (rd *Reader) MergeEnv(policies map[string]MergePolicy, vars ...[]string)

MergeEnv merges the embedded environment with the environment variables provided by the vars parameter according to the policies parameter.

func (*Reader) MergeEnvFromProfiles

func (rd *Reader) MergeEnvFromProfiles(policies map[string]MergePolicy, target profiles.Target, profileNames ...string)

MergeEnvFromProfiles merges the embedded environment with the environment variables stored in the requested profiles. The profiles are those read from the manifest. It will also expand all instances of ${JIRI_ROOT} in the returned environment.

func (*Reader) Path

func (rd *Reader) Path() string

func (*Reader) PrependToPATH

func (rd *Reader) PrependToPATH(path string)

PrependToPath prepends its argument to the PATH environment variable.

func (*Reader) ProfileNames

func (rd *Reader) ProfileNames() []string

func (*Reader) Profiles

func (rd *Reader) Profiles() []*profiles.Profile

func (*Reader) SchemaVersion

func (rd *Reader) SchemaVersion() profiles.Version

func (*Reader) SkippingProfiles

func (rd *Reader) SkippingProfiles() bool

SkippingProfiles returns true if no profiles are being used.

func (*Reader) ValidateRequestedProfilesAndTarget

func (rd *Reader) ValidateRequestedProfilesAndTarget(profileNames []string, target profiles.Target) error

ValidateRequestProfilesAndTarget checks that the supplied slice of profiles names is supported (including the 'jiri' profile) and that each has the specified target installed taking account if running using profiles at all or if using old-style profiles.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL