luci: go.chromium.org/luci/cipd/client/cipd/template Index | Files

package template

import "go.chromium.org/luci/cipd/client/cipd/template"

Package template implements handling of package name templates.

Package name templates look like e.g. "foo/${platform}" and code in this package knows how to expand them into full package names.

Index

Package Files

template.go

Variables

var ErrSkipTemplate = errors.New("package template does not apply to the current system")

ErrSkipTemplate may be returned from Expander.Expand to indicate that a given expansion doesn't apply to the current template parameters. For example, expanding `"foo/${os=linux,mac}"` with a template parameter of "os" == "win", would return ErrSkipTemplate.

type Expander Uses

type Expander map[string]string

Expander is a mapping of simple string substitutions which is used to expand cipd package name templates. For example:

ex, err := template.Expander{
  "platform": "mac-amd64"
}.Expand("foo/${platform}")

`ex` would be "foo/mac-amd64".

Use DefaultExpander() to obtain the default mapping for CIPD applications.

func DefaultExpander Uses

func DefaultExpander() Expander

DefaultExpander returns the default template expander.

This has values populated for ${os}, ${arch} and ${platform}.

func (Expander) Expand Uses

func (t Expander) Expand(template string) (pkg string, err error)

Expand applies package template expansion rules to the package template,

If err == ErrSkipTemplate, that means that this template does not apply to this os/arch combination and should be skipped.

The expansion rules are as follows:

- "some text" will pass through unchanged
- "${variable}" will directly substitute the given variable
- "${variable=val1,val2}" will substitute the given variable, if its value
  matches one of the values in the list of values. If the current value
  does not match, this returns ErrSkipTemplate.

Attempting to expand an unknown variable is an error. After expansion, any lingering '$' in the template is an error.

func (Expander) Validate Uses

func (t Expander) Validate(template string) (pkg string, err error)

Validate returns an error if this template doesn't appear to be valid given the current Expander parameters.

This will catch issues like malformed template parameters and unknown variables, and will replace all ${param=value} items with the first item in the value list, even if the current TemplateExpander value doesn't match.

This is mostly used for validating user input when the correct values of Expander aren't known yet.

type Platform Uses

type Platform struct {
    OS   string
    Arch string
}

Platform contains the parameters for a "${platform}" template.

The string value can be obtained by calling String(). be parsed using ParsePlatform.

func ParsePlatform Uses

func ParsePlatform(v string) (Platform, error)

ParsePlatform parses a Platform from its string representation.

func (Platform) Expander Uses

func (tp Platform) Expander() Expander

Expander returns an Expander populated with tp's fields.

func (Platform) String Uses

func (tp Platform) String() string

Package template imports 5 packages (graph) and is imported by 8 packages. Updated 2018-12-12. Refresh now. Tools for package owners.