config

package
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2018 License: MIT Imports: 10 Imported by: 57

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDirName is the default name used for config and workspace directories.
	DefaultDirName string
)

Functions

func DefaultWorkspaceDir

func DefaultWorkspaceDir(cfg Configuration) string

DefaultWorkspaceDir provides a sensible default for the Exercism workspace. The default is different depending on the platform, in order to best match the conventions for that platform. It places the directory in the user's home path.

func Dir

func Dir() string

Dir is the configured config home directory. All the cli-related config files live in this directory.

func InferSiteURL

func InferSiteURL(apiURL string) string

InferSiteURL guesses what the website URL is. The basis for the guess is which API we're submitting to.

func Resolve

func Resolve(path, home string) string

Resolve cleans up filesystem paths.

func SetDefaultDirName

func SetDefaultDirName(binaryName string)

SetDefaultDirName configures the default directory name based on the name of the binary.

func Write

func Write(f filer) error

Write stores the config into a file.

Types

type CLIConfig

type CLIConfig struct {
	*Config
	Tracks Tracks
}

CLIConfig contains settings specific to the behavior of the CLI.

func NewCLIConfig

func NewCLIConfig() (*CLIConfig, error)

NewCLIConfig loads the config file in the config directory.

func NewEmptyCLIConfig

func NewEmptyCLIConfig() *CLIConfig

NewEmptyCLIConfig doesn't load the config from file or set default values.

func (*CLIConfig) Load

func (cfg *CLIConfig) Load(v *viper.Viper) error

Load reads a viper configuration into the config.

func (*CLIConfig) SetDefaults

func (cfg *CLIConfig) SetDefaults()

SetDefaults ensures that we have all the necessary settings for the CLI.

func (*CLIConfig) Validate

func (cfg *CLIConfig) Validate() error

Validate ensures that the config is valid. This is called before writing it.

func (*CLIConfig) Write

func (cfg *CLIConfig) Write() error

Write stores the config to disk.

type Config

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

Config is a wrapper around a viper configuration.

func New

func New(dir, name string) *Config

New creates a default config value for the given directory.

func (*Config) File

func (cfg *Config) File() string

File is the full path to the config file.

type Configuration

type Configuration struct {
	OS              string
	Home            string
	Dir             string
	DefaultBaseURL  string
	DefaultDirName  string
	UserViperConfig *viper.Viper
	UserConfig      *UserConfig
	CLIConfig       *CLIConfig
	Persister       Persister
}

Configuration lets us inject configuration options into commands. Note that we are slowly working towards getting rid of the config.Config, config.UserConfig, and config.CLIConfig types. Once we do, we can rename this type to Config, and get rid of the User and CLI fields.

func NewConfiguration

func NewConfiguration() Configuration

NewConfiguration provides a configuration with default values.

func (Configuration) Save

func (c Configuration) Save(basename string) error

Save persists a viper config of the base name.

type FilePersister

type FilePersister struct {
	Dir string
}

FilePersister saves viper configs to the file system.

func (FilePersister) Save

func (p FilePersister) Save(v *viper.Viper, basename string) error

Save writes the viper config to the target location on the filesystem.

type InMemoryPersister

type InMemoryPersister struct{}

InMemoryPersister is a noop persister for use in unit tests.

func (InMemoryPersister) Save

Save does nothing.

type Persister

type Persister interface {
	Save(*viper.Viper, string) error
}

Persister saves viper configs.

type Track

type Track struct {
	ID             string
	IgnorePatterns []string
	// contains filtered or unexported fields
}

Track holds the CLI-related settings for a track.

func NewTrack

func NewTrack(id string) *Track

NewTrack provides a track configured with default values.

func (*Track) AcceptFilename

func (t *Track) AcceptFilename(f string) (bool, error)

AcceptFilename judges a files admissability based on the name.

func (*Track) CompileRegexes

func (t *Track) CompileRegexes() error

CompileRegexes precompiles the ignore patterns.

func (*Track) SetDefaults

func (t *Track) SetDefaults()

SetDefaults configures a track with default values.

type Tracks

type Tracks map[string]*Track

Tracks is a collection of track-specific settings.

type UserConfig

type UserConfig struct {
	*Config
	Workspace  string
	Token      string
	Home       string
	APIBaseURL string
	// contains filtered or unexported fields
}

UserConfig contains user-specific settings.

func NewEmptyUserConfig

func NewEmptyUserConfig() *UserConfig

NewEmptyUserConfig creates a user configuration without loading it.

func NewUserConfig

func NewUserConfig() (*UserConfig, error)

NewUserConfig loads a user configuration if it exists.

func (*UserConfig) Load

func (cfg *UserConfig) Load(v *viper.Viper) error

Load reads a viper configuration into the config.

func (*UserConfig) SetDefaults

func (cfg *UserConfig) SetDefaults()

SetDefaults ensures that we have proper values where possible.

func (*UserConfig) Write

func (cfg *UserConfig) Write() error

Write stores the config to disk.

Jump to

Keyboard shortcuts

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