config

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Init function is to setup config paths and their ENV binding. Should just be called once.

func Load

func Load(runValidation bool) error

Load uses viper, loads it and sets the output in Cfg

func SetDefaultValues

func SetDefaultValues()

SetDefaultValues sets the default values for the config keys managed with viper.

Types

type Config

type Config struct {
	FirstVersion  string `mapstructure:"first_version" validate="required"`
	GitExecutable string `mapstructure:"git_executable" validate="required"`
	GitRemote     string `mapstructure:"git_remote" validate="required"`
	GitRepoURL    string `mapstructure:"git_repo_url"`
	LatestVersion string `mapstructure:"latest_version"`
	NewVersion    string `mapstructure:"new_version"`
	// Rules defines rule sets for different paths
	Rules []Rule `mapstructure:"rules" yaml:"rules"`
}

Config is the application configuration data struct

var (
	// Cfg is the global instance of Config
	Cfg *Config
)

func Get

func Get() *Config

Get returns Cfg var

func (Config) GetMatchingPathRule added in v0.0.11

func (c Config) GetMatchingPathRule(p string) (Rule, error)

GetMatchingPathRule returns first Rule of the Config where MatchesWithPath is true

func (Config) ValidateRules added in v0.0.11

func (c Config) ValidateRules() error

ValidateRules runs Validate function on each entry in Rules list of Config instance

type DynamicFlag added in v0.0.11

type DynamicFlag struct {
	// Name of the itself
	Name string `validate:"required,alpha,lowercase"`
	// Default is an optional default value which should always be used for the flag
	Default string
	// Description of the flag itself (optional)
	Description string

	Required bool

	// SkipForBranch will not use this flag for any branch releated command and operation
	SkipForBranch bool `mapstructure:"skip_for_branch" yaml="skip_for_branch"`
	// SkipForCommit will not use this flag for any commit releated command and operation
	SkipForCommit bool `mapstructure:"skip_for_commit" yaml="skip_for_commit"`
}

DynamicFlag holds a config for a dynamic flag which applies for a certain path. It should be used within a Rule.

func (DynamicFlag) Validate added in v0.0.11

func (d DynamicFlag) Validate() error

Validate runs the validators of the DynamicFlag instance

type Rule added in v0.0.11

type Rule struct {
	// A list of dynamic flags which are added to certain commands under the given paths.
	Flags []DynamicFlag `mapstructure:"flags" yaml:"flags"`
	// GitBranchDefaultType  defines the default type of branch that should be used
	GitBranchDefaultType string `mapstructure:"git_branch_default_type" yaml:"git_branch_default_type"`
	// GitBranchDelimiter defines the sign which connects certain parts of the branch name.
	// It just can be one sign and only one of '-', '_', '/' '+'. Default is '-'
	GitBranchDelimiter string `mapstructure:"git_branch_delimiter" validate:"omitempty,max=1,oneof='-' '_' '/' '+'" yaml:"git_branch_delimiter"`
	// GitBranchForceType: if true a type for the branch needs always to be set
	GitBranchForceType bool `mapstructure:"git_branch_force_type" yaml:"git_branch_force_type"`
	// GitBranchPrefix defines the prefix which is set for a branch name
	GitBranchPrefix string `mapstructure:"git_branch_prefix" yaml:"git_branch_prefix"`
	// GitBranchSuffix defines the suffix which is set for a branch name
	GitBranchSuffix string `mapstructure:"git_branch_suffix" yaml:"git_branch_suffix"`
	// GitBranchTypes defines the overwrites of available types. If not set the defaults are:
	// feature, bug, hotfix
	GitBranchTypes []string `mapstructure:"git_branch_types" validate:"unique,dive,lowercase,alpha" yaml:"git_branch_types"`
	// Paths are the paths with certain rules to which this rule should be applied to
	Paths []string `mapstructure:"paths" yaml:"paths"`
}

Rule is a struct of settings and rules for a certain path

func (Rule) FlagNames added in v0.0.11

func (r Rule) FlagNames() []string

FlagNames returns the Name attribute of each element in r.Flags

func (Rule) FlagNamesForBranch added in v0.0.11

func (r Rule) FlagNamesForBranch() []string

FlagNamesForBranch returns the Name attribute of each element in r.FlagNamesForBranch

func (Rule) FlagNamesForCommit added in v0.0.11

func (r Rule) FlagNamesForCommit() []string

FlagNamesForCommit returns the Name attribute of each element in r.FlagNamesForCommit

func (Rule) FlagsForBranch added in v0.0.11

func (r Rule) FlagsForBranch() []DynamicFlag

FlagsForBranch will only return entries of r.Flags list where SkipForBranch is false

func (Rule) FlagsForCommit added in v0.0.11

func (r Rule) FlagsForCommit() []DynamicFlag

FlagsForCommit will only return entries of r.Flags list where SkipForCommit is false

func (Rule) GetGitBranchDelimiter added in v0.0.11

func (r Rule) GetGitBranchDelimiter() string

GetGitBranchDelimiter returns the defined r.GitBranchDelimiter or "-" as default

func (Rule) GetGitBranchTypes added in v0.0.11

func (r Rule) GetGitBranchTypes() []string

GetGitBranchTypes returns either r.GitBranchTypes or the default ones

func (Rule) MatchesWithPath added in v0.0.11

func (r Rule) MatchesWithPath(p string) (bool, error)

MatchesWithPath checks if a given path matches with any of the defined path rules

func (Rule) ParsedPaths added in v0.0.11

func (r Rule) ParsedPaths() ([]string, error)

ParsedPaths returns the Paths list with parsed variables of the Rule instance

func (Rule) Validate added in v0.0.11

func (r Rule) Validate() error

Validate runs the validators of the Rule instance

Jump to

Keyboard shortcuts

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