pkg

package
v0.0.0-...-35906d0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigExists         = errors.New(".envsnap file already exists")
	ErrNoConfig             = errors.New(".envsnap file not found")
	ErrUnsupportedLang      = errors.New("unsupported language passed to the --lang flag")
	ErrIncompleteRender     = errors.New("envsnap failed to render some configured options (run with --debug for more detail)")
	ErrUnsupportedFormat    = errors.New("unsupported format string provided")
	ErrNoConfigVersion      = errors.New("no version specified in config")
	ErrInvalidConfigVersion = errors.New("invalid config version specified")
	ErrInvalidGithubURL     = errors.New("invalid github url: must be in the format 'github.com/<user>/<repo>'")
)

Errors used throughout envsnap.

View Source
var (
	Version   string
	Commit    string
	Tag       string
	GoVersion string
	BuildDate string
)

Build-time arguments are used to populate these variables to generate build-specific version information.

View Source
var AppHelpTemplate = heredoc.Doc(`
	Usage: {{ .HelpName }} [global options] command [command options] [arguments ...]
	
	{{ .Usage }}
	
	Commands:{{range .VisibleCategories}}{{if .Name}}
	
	   {{.Name}}:{{range .VisibleCommands}}
		 {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
	   {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
	
	Options:
	   {{range $index, $option := .VisibleFlags}}{{if $index}}
	   {{end}}{{$option}}{{end}}{{end}}	
	
	Run '{{ .HelpName }} [command] --help' for more information about a command.
`)

AppHelpTemplate is a custom template for the CLI help message.

View Source
var CommandHelpTemplate = heredoc.Doc(`
	Usage: {{ .HelpName }}{{ if .VisibleFlags }} [options]{{ end }} {{ if .ArgsUsage }}{{ .ArgsUsage }}{{ else }}[arguments...]{{ end }}
	
	{{ .Usage }}{{ if .Description }}
	
	{{ .Description }}{{ end }}{{if .VisibleFlags}}
	
	Options:
	   {{range .VisibleFlags}}{{.}}
	   {{end}}{{end}}
`)

CommandHelpTemplate is a custom template for the CLI command help messages.

View Source
var CommandVersionTemplate = heredoc.Doc(`
	envsnap:
	  version:      {{ .Version }}
	  build date:   {{ .BuildDate }}
	  commit:       {{ .Commit }}
	  tag:          {{ .Tag }}
	  go version:   {{ .GoVersion }}
	  go compiler:  {{ .Compiler }}
	  platform:     {{ .OS }}/{{ .Arch }}
`)

CommandVersionTemplate is the template for the CLI version output.

View Source
var EnvsnapInitTemplate = heredoc.Doc(`
	# envsnap configuration (yaml format)
	# use 'envsnap show' to generate an environment snapshot
	# for more details, see: https://www.github.com/edaniszewski/envsnap
	
	version: {{ .Version }}
	{{ if not .Terse }}
	# System configurations provide details about the user's system.{{ end }}
	system:
	  core:
	  - os
	  - arch
	{{ if .RenderPython -}}
	{{ if not .Terse }}
	# Python configurations provide details about the user's Python
	# installation and dependencies.{{ end }}
	python:
	  core:
	  - version
	  dependencies: []
	{{ end }}{{ if .RenderGolang -}}
	{{ if not .Terse }}
	# Golang configurations provide details about the user's Go installation.{{ end }}
	go:
	  core:
	  - version
	{{ end -}}
`)

EnvsnapInitTemplate is the template for the boilerplate envsnap config.

Functions

func NewApp

func NewApp() *cli.App

NewApp creates a new instance of the envsnap CLI application.

func NewTabWriter

func NewTabWriter(out io.Writer) *tabwriter.Writer

NewTabWriter creates a tabwriter with default configurations to align input text into tab-spaced columns.

Types

type DependenciesConfig

type DependenciesConfig struct {
	Packages []string `yaml:"packages,omitempty"`
}

DependenciesConfig defines the Python configuration for specifying package dependencies.

type EnvConfig

type EnvConfig struct {
	Variables []string `yaml:"variables,omitempty"`
}

EnvConfig defines the configuration for the "environment" source.

func (EnvConfig) Render

func (c EnvConfig) Render() (Result, error)

Render the EnvConfig into its corresponding EnvResult.

type EnvResult

type EnvResult struct {
	// Common
	ResultCommon `json:"-" yaml:"-"`

	// Env
	Env map[string]string `yaml:",omitempty,inline" json:"env,omitempty"`
}

EnvResult contains the result data from rendering an "environment" source.

func NewEnvResult

func NewEnvResult() EnvResult

NewEnvResult creates a new instance of an EnvResult.

func (EnvResult) IsEmpty

func (r EnvResult) IsEmpty() bool

IsEmpty checks whether the result contains any data.

func (EnvResult) JSON

func (r EnvResult) JSON() ([]byte, error)

JSON renders the EnvResult to JSON.

func (EnvResult) Markdown

func (r EnvResult) Markdown() ([]byte, error)

Markdown renders the EnvResult to markdown.

func (EnvResult) Plaintext

func (r EnvResult) Plaintext() ([]byte, error)

Plaintext renders the EnvResult to plaintext.

func (EnvResult) YAML

func (r EnvResult) YAML() ([]byte, error)

YAML renders the EnvResult to YAML.

type EnvsnapConfig

type EnvsnapConfig interface {
	All() []RenderConfig
	Render() (EnvsnapResult, error)
}

EnvsnapConfig defines an interface which all versions of the envsnap configuration should implement.

func LoadConfig

func LoadConfig(path string) (EnvsnapConfig, error)

LoadConfig loads the configuration for envsnap to render.

If no path is specified, it assumes the configuration is in the current working directory. The path may also be a reference to a GitHub repository containing the configuration, in the form of "github.com/<owner>/<repo>[@<ref>]" where the <ref> may be a branch name, tag, or commit.

type EnvsnapResult

type EnvsnapResult interface {
	Results() []Result
	String(format string) (string, error)
	Write(file, format string) error
	Print(format string) error
}

EnvsnapResult defines an interface which all versions of envsnap results should implement.

type ExecConfig

type ExecConfig struct {
	Run []string `yaml:"run,omitempty"`
}

ExecConfig defines the configuration for the "exec" source.

func (ExecConfig) Render

func (c ExecConfig) Render() (Result, error)

Render the ExecConfig into its corresponding ExecResult.

type ExecResult

type ExecResult struct {
	// Common
	ResultCommon `json:"-" yaml:"-"`

	// Exec
	Exec map[string]string `yaml:"exec,omitempty" json:"exec,omitempty"`
}

ExecResult contains the result data from rendering an "exec" source.

func NewExecResult

func NewExecResult() ExecResult

NewExecResult creates a new instance of an ExecResult.

func (ExecResult) IsEmpty

func (r ExecResult) IsEmpty() bool

IsEmpty checks whether the result contains any data.

func (ExecResult) JSON

func (r ExecResult) JSON() ([]byte, error)

JSON renders the ExecResult to JSON.

func (ExecResult) Markdown

func (r ExecResult) Markdown() ([]byte, error)

Markdown renders the ExecResult to markdown.

func (ExecResult) Plaintext

func (r ExecResult) Plaintext() ([]byte, error)

Plaintext renders the ExecResult to plaintext.

func (ExecResult) YAML

func (r ExecResult) YAML() ([]byte, error)

YAML renders the ExecResult to YAML.

type GolangConfig

type GolangConfig struct {
	Core []string `yaml:"core,omitempty"`
}

GolangConfig defines the configuration for the "go" source.

func (GolangConfig) Render

func (c GolangConfig) Render() (Result, error)

Render the GolangConfig into its corresponding GolangResult.

type GolangResult

type GolangResult struct {
	// Common
	ResultCommon `json:"-" yaml:"-"`

	// Core
	Version string `yaml:"version,omitempty" json:"version,omitempty"`
	Goroot  string `yaml:"goroot,omitempty" json:"goroot,omitempty"`
	Gopath  string `yaml:"gopath,omitempty" json:"gopath,omitempty"`
}

GolangResult contains the result data from rendering an "go" source.

func NewGolangResult

func NewGolangResult() GolangResult

NewGolangResult creates a new instance of an GolangResult.

func (GolangResult) IsEmpty

func (r GolangResult) IsEmpty() bool

IsEmpty checks whether the result contains any data.

func (GolangResult) JSON

func (r GolangResult) JSON() ([]byte, error)

JSON renders the GolangResult to JSON.

func (GolangResult) Markdown

func (r GolangResult) Markdown() ([]byte, error)

Markdown renders the GolangResult to markdown.

func (GolangResult) Plaintext

func (r GolangResult) Plaintext() ([]byte, error)

Plaintext renders the GolangResult to plaintext.

func (GolangResult) YAML

func (r GolangResult) YAML() ([]byte, error)

YAML renders the GolangResult to YAML.

type InitOptions

type InitOptions struct {
	Version int
	Terse   bool

	RenderPython bool
	RenderGolang bool
}

InitOptions are the options used to render the .envsnap config boilerplate via `envsnap init`.

type PythonConfig

type PythonConfig struct {
	Core []string           `yaml:"core,omitempty"`
	Deps DependenciesConfig `yaml:"dependencies,omitempty"`
}

PythonConfig defines the configuration for the "python" source.

func (PythonConfig) Render

func (c PythonConfig) Render() (Result, error)

Render the PythonConfig into its corresponding PythonResult.

type PythonResult

type PythonResult struct {
	// Common
	ResultCommon `json:"-" yaml:"-"`

	// Core
	Version    string `yaml:"version,omitempty" json:"version,omitempty"`
	VersionPy2 string `yaml:"py2,omitempty" json:"py2,omitempty"`
	VersionPy3 string `yaml:"py3,omitempty" json:"py3,omitempty"`

	// Dependencies
	Deps map[string]string `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
}

PythonResult contains the result data from rendering an "python" source.

func NewPythonResult

func NewPythonResult() PythonResult

NewPythonResult creates a new instance of an PythonResult.

func (PythonResult) IsEmpty

func (r PythonResult) IsEmpty() bool

IsEmpty checks whether the result contains any data.

func (PythonResult) JSON

func (r PythonResult) JSON() ([]byte, error)

JSON renders the PythonResult to JSON.

func (PythonResult) Markdown

func (r PythonResult) Markdown() ([]byte, error)

Markdown renders the PythonResult to markdown.

func (PythonResult) Plaintext

func (r PythonResult) Plaintext() ([]byte, error)

Plaintext renders the PythonResult to plaintext.

func (PythonResult) YAML

func (r PythonResult) YAML() ([]byte, error)

YAML renders the PythonResult to YAML.

type RenderConfig

type RenderConfig interface {
	Render() (Result, error)
}

RenderConfig defines an interface for configuration sections for envsnap which can be rendered into results.

type Result

type Result interface {
	IsEmpty() bool

	Markdown() ([]byte, error)
	Plaintext() ([]byte, error)
	YAML() ([]byte, error)
	JSON() ([]byte, error)
}

Result defines an interface for rendered configurations which allows them to be output in a number of supported formats.

type ResultCommon

type ResultCommon struct {
	// TODO move somewhere outside of interface
	CodeQuote string
	CodeFence string
}

ResultCommon is a struct which defines common components to results which instances of a Result may embed to access the fields here for output formatting, particularly for markdown.

type SysInfo

type SysInfo struct {
	OS            string
	Kernel        string
	KernelVersion string
	Arch          string
	Processor     string
}

SysInfo contains information about the system.

func LoadSystemInfo

func LoadSystemInfo() (SysInfo, error)

LoadSystemInfo loads the system info (os, arch, etc) into a SysInfo struct.

type SystemConfig

type SystemConfig struct {
	Core []string `yaml:"core,omitempty"`
}

SystemConfig defines the configuration for the "system" source.

func (SystemConfig) Render

func (c SystemConfig) Render() (Result, error)

Render the SystemConfig into its corresponding SystemResult.

type SystemResult

type SystemResult struct {
	// Common
	ResultCommon `json:"-" yaml:"-"`

	// Core
	OS            string `yaml:"os,omitempty" json:"os,omitempty"`
	Arch          string `yaml:"arch,omitempty" json:"arch,omitempty"`
	CPUs          int    `yaml:"cpus,omitempty" json:"cpus,omitempty"`
	Kernel        string `yaml:"kernel,omitempty" json:"kernel,omitempty"`
	KernelVersion string `yaml:"kernel_version,omitempty" json:"kernel_version,omitempty"`
	Processor     string `yaml:"processor,omitempty" json:"processor,omitempty"`
}

SystemResult contains the result data from rendering an "system" source.

func NewSystemResult

func NewSystemResult() SystemResult

NewSystemResult creates a new instance of an SystemResult.

func (SystemResult) IsEmpty

func (r SystemResult) IsEmpty() bool

IsEmpty checks whether the result contains any data.

func (SystemResult) JSON

func (r SystemResult) JSON() ([]byte, error)

JSON renders the SystemResult to JSON.

func (SystemResult) Markdown

func (r SystemResult) Markdown() ([]byte, error)

Markdown renders the SystemResult to markdown.

func (SystemResult) Plaintext

func (r SystemResult) Plaintext() ([]byte, error)

Plaintext renders the SystemResult to plaintext.

func (SystemResult) YAML

func (r SystemResult) YAML() ([]byte, error)

YAML renders the SystemResult to YAML.

type V1EnvsnapConfig

type V1EnvsnapConfig struct {
	Environment EnvConfig    `yaml:"environment,omitempty"`
	Exec        ExecConfig   `yaml:"exec,omitempty"`
	Golang      GolangConfig `yaml:"go,omitempty"`
	Python      PythonConfig `yaml:"python,omitempty"`
	System      SystemConfig `yaml:"system,omitempty"`
}

V1EnvsnapConfig contains all the data for the environment snapshot.

func (V1EnvsnapConfig) All

func (c V1EnvsnapConfig) All() []RenderConfig

All returns all of the configuration components for the v1 envsnap config.

func (V1EnvsnapConfig) Render

func (c V1EnvsnapConfig) Render() (EnvsnapResult, error)

Render each configured source into its corresponding v1 result.

type V1EnvsnapResult

type V1EnvsnapResult struct {
	Environment Result `json:"environment,omitempty" yaml:"environment,omitempty"`
	Exec        Result `json:"exec,omitempty" yaml:"exec,omitempty"`
	Golang      Result `json:"golang,omitempty" yaml:"golang,omitempty"`
	Python      Result `json:"python,omitempty" yaml:"python,omitempty"`
	System      Result `json:"system,omitempty" yaml:"system,omitempty"`
	// contains filtered or unexported fields
}

V1EnvsnapResult contains the results for all sources specified by version 1 of the envsnap configuration, as defined in V1EnvsnapConfig.

func NewV1EnvsnapResult

func NewV1EnvsnapResult() V1EnvsnapResult

NewV1EnvsnapResult creates a new instance of the V1EnvsnapResult struct, setting the default `out` to stdout.

func (*V1EnvsnapResult) Print

func (r *V1EnvsnapResult) Print(format string) error

Print renders the result into a string based on the provided format and writes that string to stdout.

func (*V1EnvsnapResult) Results

func (r *V1EnvsnapResult) Results() []Result

Results returns all of the component source results in the order in which they should be rendered.

func (*V1EnvsnapResult) String

func (r *V1EnvsnapResult) String(format string) (string, error)

String renders the result into a string based on the given format option. If the provided format is not supported, this returns an error.

func (*V1EnvsnapResult) Write

func (r *V1EnvsnapResult) Write(file, format string) error

Write renders the result into a string based on the provided format and writes that string to the specified file.

type VersionedConfig

type VersionedConfig struct {
	Version *int `yaml:"version"`
}

VersionedConfig is an intermediary struct which is used to load the version information from configuration YAML. This allows envsnap to determine the version of the configuration, and thus the correct struct to load the configuration into.

type Warnings

type Warnings struct {
	Warnings map[string][]string
}

Warnings contains a collection of warnings and their sources.

This is used to collect warnings during the envsnap render. The source of the warning is the key, and the string which describes the warning itself is kept in the value. A warning source may have multiple warnings associated with it.

func NewWarnings

func NewWarnings() *Warnings

NewWarnings creates a new instance of a Warnings struct, used to accumulate and print warnings.

func (*Warnings) Add

func (w *Warnings) Add(src string, msg string, a ...interface{})

Add a new warning.

The source should describe which component/area the warning was generated from. The message should be the warning itself, describing what is wrong. The message may be a format string, in which case the format components may be passed along as well.

func (*Warnings) Clear

func (w *Warnings) Clear()

Clear all collected warnings.

func (*Warnings) HasWarnings

func (w *Warnings) HasWarnings() bool

HasWarnings checks to see whether the Warnings instance has any tracked warnings.

func (*Warnings) Print

func (w *Warnings) Print(writer io.Writer)

Print out the tracked warnings.

The printed message is formatted with color and in a tabular view. Warnings are sorted alphabetically first by source, then by warning message.

Jump to

Keyboard shortcuts

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