context

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLogLevel is the default level to output log
	DefaultLogLevel = "warn"
	// DefaultGitHubHost is the default host of the GitHub
	DefaultGitHubHost = "github.com"
)
View Source
const FileModeSeparator = '|'

Variables

View Source
var (
	ErrEmptyValue        = errors.New("empty value")
	ErrInvalidOptionName = errors.New("invalid option name")
)
View Source
var (
	TrueOption      = BoolOption("yes")
	FalseOption     = BoolOption("no")
	EmptyBoolOption = BoolOption("")
)
View Source
var (
	// DefaultHistoryFile is the default file to save history
	DefaultHistoryFile = filepath.Join(xdg.CacheHome(), "gordon", "history")
)

Functions

func OptionNames

func OptionNames() []string

func SaveConfig

func SaveConfig(w io.Writer, config *Config) error

func ValidateArchitecture

func ValidateArchitecture(arch string) error

func ValidateContext

func ValidateContext(ctx Context) error

func ValidateDist

func ValidateDist(os, arch string) error

func ValidateFile

func ValidateFile(file string) error

func ValidateLogLevel

func ValidateLogLevel(level string) error

func ValidateOS

func ValidateOS(os string) error

func ValidateOwner

func ValidateOwner(owner string) error

func ValidateRegexp

func ValidateRegexp(pattern string) error

func ValidateRoot

func ValidateRoot(root string) error

Types

type BoolOption

type BoolOption string

func (BoolOption) Bool

func (c BoolOption) Bool() bool

func (*BoolOption) Decode

func (c *BoolOption) Decode(repl string) error

Decode implements the interface `envdecode.Decoder`

func (BoolOption) MarshalText

func (c BoolOption) MarshalText() ([]byte, error)

MarshalText implements the interface `encoding.TextMarshaler`

func (*BoolOption) SetBool

func (c *BoolOption) SetBool(b bool)

func (BoolOption) String

func (c BoolOption) String() string

func (*BoolOption) UnmarshalText

func (c *BoolOption) UnmarshalText(raw []byte) error

UnmarshalText implements the interface `encoding.TextUnmarshaler`

type Config

type Config struct {
	context.Context `yaml:"-"`
	Log             LogConfig     `yaml:"log,omitempty"`
	GitHub          GitHubConfig  `yaml:"github,omitempty"`
	History         HistoryConfig `yaml:"history,omitempty"`
	Extract         ExtractConfig `yaml:"extract,omitempty"`
	VRoot           string        `yaml:"root,omitempty" env:"GORDON_ROOT"`
	VArchitecture   string        `yaml:"architecture,omitempty" env:"GORDON_ARCHITECTURE"`
	VOS             string        `yaml:"os,omitempty" env:"GORDON_OS"`
}

Config holds configuration file values.

func DefaultConfig

func DefaultConfig() *Config

func GetEnvarConfig

func GetEnvarConfig() (config *Config, err error)

func LoadConfig

func LoadConfig(r io.Reader) (config *Config, err error)

func LoadKeyring

func LoadKeyring() *Config

func MergeConfig

func MergeConfig(base *Config, override ...*Config) *Config

func (*Config) Architecture

func (c *Config) Architecture() string

func (*Config) ExtractExclude

func (c *Config) ExtractExclude() string

func (*Config) ExtractInclude

func (c *Config) ExtractInclude() string

func (*Config) ExtractModes

func (c *Config) ExtractModes() FileModes

func (*Config) GitHubHost

func (c *Config) GitHubHost() string

func (*Config) GitHubToken

func (c *Config) GitHubToken() string

func (*Config) GitHubUser

func (c *Config) GitHubUser() string

func (*Config) HistoryFile

func (c *Config) HistoryFile() string

func (*Config) HistorySave

func (c *Config) HistorySave() bool

func (*Config) LogDate

func (c *Config) LogDate() bool

func (*Config) LogFlags

func (c *Config) LogFlags() int

func (*Config) LogLevel

func (c *Config) LogLevel() string

func (*Config) LogLongFile

func (c *Config) LogLongFile() bool

func (*Config) LogMicroSeconds

func (c *Config) LogMicroSeconds() bool

func (*Config) LogShortFile

func (c *Config) LogShortFile() bool

func (*Config) LogTime

func (c *Config) LogTime() bool

func (*Config) LogUTC

func (c *Config) LogUTC() bool

func (*Config) OS

func (c *Config) OS() string

func (*Config) Root

func (c *Config) Root() string

func (*Config) Stderr

func (c *Config) Stderr() io.Writer

func (*Config) Stdin

func (c *Config) Stdin() io.Reader

func (*Config) Stdout

func (c *Config) Stdout() io.Writer

type Context

type Context interface {
	context.Context
	IOContext
	LogContext
	GitHubContext
	HistoryContext
	ExtractContext
	Root() string
	Architecture() string
	OS() string
}

Context holds configurations and environments

type ExtractConfig

type ExtractConfig struct {
	Modes   FileModes `yaml:"modes,omitempty" env:"GORDON_EXTRACT_MODES"`
	Exclude string    `yaml:"exclude,omitempty" env:"GORDON_EXTRACT_EXCLUDE"`
	Include string    `yaml:"include,omitempty" env:"GORDON_EXTRACT_INCLUDE"`
}

type ExtractContext

type ExtractContext interface {
	ExtractModes() FileModes
	ExtractExclude() string
	ExtractInclude() string
}

type FileMode

type FileMode os.FileMode

func (FileMode) MarshalText

func (f FileMode) MarshalText() ([]byte, error)

func (FileMode) Match

func (f FileMode) Match(m os.FileMode) bool

func (*FileMode) UnmarshalText

func (f *FileMode) UnmarshalText(raw []byte) error

type FileModes

type FileModes []FileMode

func (FileModes) MarshalText

func (filters FileModes) MarshalText() ([]byte, error)

func (FileModes) Match

func (filters FileModes) Match(m os.FileMode) bool

func (*FileModes) UnmarshalText

func (filters *FileModes) UnmarshalText(raw []byte) error

type GitHubConfig

type GitHubConfig struct {
	Token string `yaml:"-" env:"GORDON_GITHUB_TOKEN"`
	User  string `yaml:"user,omitempty" env:"GORDON_GITHUB_USER"`
	Host  string `yaml:"host,omitempty" env:"GORDON_GITHUB_HOST"`
}

type GitHubContext

type GitHubContext interface {
	GitHubUser() string
	GitHubToken() string
	GitHubHost() string
}

type HistoryConfig

type HistoryConfig struct {
	File string     `yaml:"file,omitempty" env:"GORDON_HISTORY_FILE"`
	Save BoolOption `yaml:"save" env:"GORDON_HISTORY_SAVE"`
}

type HistoryContext

type HistoryContext interface {
	HistoryFile() string
	HistorySave() bool
}

type IOContext

type IOContext interface {
	Stdin() io.Reader
	Stdout() io.Writer
	Stderr() io.Writer
}

type LogConfig

type LogConfig struct {
	Level        string     `yaml:"level,omitempty" env:"GORDON_LOG_LEVEL"`
	Date         BoolOption `yaml:"date" env:"GORDON_LOG_DATE"`                 // the date in the local time zone: 2009/01/23
	Time         BoolOption `yaml:"time" env:"GORDON_LOG_TIME"`                 // the time in the local time zone: 01:23:23
	MicroSeconds BoolOption `yaml:"microseconds" env:"GORDON_LOG_MICROSECONDS"` // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	LongFile     BoolOption `yaml:"longfile" env:"GORDON_LOG_LONGFILE"`         // full file name and line number: /a/b/c/d.go:23
	ShortFile    BoolOption `yaml:"shortfile" env:"GORDON_LOG_SHORTFILE"`       // final file name element and line number: d.go:23. overrides Llongfile
	UTC          BoolOption `yaml:"utc" env:"GORDON_LOG_UTC"`                   // if Ldate or Ltime is set, use UTC rather than the local time zone
}

type LogContext

type LogContext interface {
	LogLevel() string
	LogFlags() int // log.Lxxx flags
	LogDate() bool
	LogTime() bool
	LogMicroSeconds() bool
	LogLongFile() bool
	LogShortFile() bool
	LogUTC() bool
}

type MockContext

type MockContext struct {
	context.Context
	MStdin           io.Reader
	MStdout          io.Writer
	MStderr          io.Writer
	MLogLevel        string
	MLogFlags        int
	MLogDate         bool
	MLogTime         bool
	MLogMicroSeconds bool
	MLogLongFile     bool
	MLogShortFile    bool
	MLogUTC          bool
	MGitHubUser      string
	MGitHubToken     string
	MGitHubHost      string
	MHistoryFile     string
	MHistorySave     bool
	MExtractModes    FileModes
	MExtractExclude  string
	MExtractInclude  string
	MRoot            string
	MArchitecture    string
	MOS              string
}

func (*MockContext) Architecture

func (c *MockContext) Architecture() string

func (*MockContext) ExtractExclude

func (c *MockContext) ExtractExclude() string

func (*MockContext) ExtractInclude

func (c *MockContext) ExtractInclude() string

func (*MockContext) ExtractModes

func (c *MockContext) ExtractModes() FileModes

func (*MockContext) GitHubHost

func (c *MockContext) GitHubHost() string

func (*MockContext) GitHubToken

func (c *MockContext) GitHubToken() string

func (*MockContext) GitHubUser

func (c *MockContext) GitHubUser() string

func (*MockContext) HistoryFile

func (c *MockContext) HistoryFile() string

func (*MockContext) HistorySave

func (c *MockContext) HistorySave() bool

func (*MockContext) LogDate

func (c *MockContext) LogDate() bool

func (*MockContext) LogFlags

func (c *MockContext) LogFlags() int

func (*MockContext) LogLevel

func (c *MockContext) LogLevel() string

func (*MockContext) LogLongFile

func (c *MockContext) LogLongFile() bool

func (*MockContext) LogMicroSeconds

func (c *MockContext) LogMicroSeconds() bool

func (*MockContext) LogShortFile

func (c *MockContext) LogShortFile() bool

func (*MockContext) LogTime

func (c *MockContext) LogTime() bool

func (*MockContext) LogUTC

func (c *MockContext) LogUTC() bool

func (*MockContext) OS

func (c *MockContext) OS() string

func (*MockContext) Root

func (c *MockContext) Root() string

func (*MockContext) Stderr

func (c *MockContext) Stderr() io.Writer

func (*MockContext) Stdin

func (c *MockContext) Stdin() io.Reader

func (*MockContext) Stdout

func (c *MockContext) Stdout() io.Writer

type OptionAccessor

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

func Option

func Option(optionName string) (*OptionAccessor, error)

func Options

func Options() []OptionAccessor

func (OptionAccessor) Get

func (a OptionAccessor) Get(cfg *Config) string

func (OptionAccessor) Prompt

func (a OptionAccessor) Prompt(cfg *Config) error

func (OptionAccessor) Put

func (a OptionAccessor) Put(cfg *Config, value string) error

func (OptionAccessor) Unset

func (a OptionAccessor) Unset(cfg *Config) error

Jump to

Keyboard shortcuts

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