config

package
v0.0.0-...-44808bf Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package config handles the configuration files.

Index

Constants

This section is empty.

Variables

View Source
var Defaults value.DB = value.DB{}

Defaults contains some default values.

Functions

This section is empty.

Types

type Config

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

Config is the main configuration manager.

func New

func New() *Config

New creates a new Config object with the global handler attached to it. So _ALL_ instances will work on the same data.

func (*Config) Copy

func (c *Config) Copy() *Config

Copy creates a new Config object with a copy of the data handler, so we can detach from the global parser.

func (*Config) HasOption

func (c *Config) HasOption(section, option string) bool

HasOption checks if option exists in section.

func (*Config) HasSection

func (c *Config) HasSection(name string) bool

HasSection checks if the section exists in the global parser.

func (*Config) Load

func (c *Config) Load() error

Load reads the configuration files from the provided profile.

func (*Config) Read

func (c *Config) Read(r io.Reader) error

Read reads config content from reader.

func (*Config) Save

func (c *Config) Save() error

Save writes configuration to the provided profile.

func (*Config) Section

func (c *Config) Section(name string) *Section

Section creates a new Section object with its named section data attached to it. If the section name does not exists, "default" is used.

func (*Config) SetDefaults

func (c *Config) SetDefaults(v value.DB)

SetDefaults set the values from the Defaults global variable. If a section already exists, it will be overriden.

func (*Config) Write

func (c *Config) Write(w io.Writer) error

Write writes config content to writer.

type Flags

type Flags struct {
	Quiet   bool
	Debug   bool
	Info    bool
	Verbose bool
	Name    string
	Profile *profile.Profile
}

Flags holds some configuration settings that can be overriden from cmd args.

func NewFlags

func NewFlags(fs *flag.FlagSet) *Flags

NewFlags creates a new Flags object and sets the flags to the provided handler.

func (*Flags) Parse

func (f *Flags) Parse() error

Parse parses the flags.

type Parser

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

func NewParser

func NewParser(c *Config) *Parser

func (*Parser) Map

func (p *Parser) Map(filter string) map[string]string

Map returns a map with section.option as keys with their respective values from the global parser object. The filter string can be empty "" or contain the prefix of the values to filter. In example, if filter is "master", only values from master section ("master.*") will be returned.

func (*Parser) Set

func (p *Parser) Set(option, val string) error

Set sets section.option with provided value. It's an error if the option already exists.

func (*Parser) Unset

func (p *Parser) Unset(option string) error

Unset removes section.option.

func (*Parser) Update

func (p *Parser) Update(option, newval string) error

Update updates section.option on the global parser object with the new provided value. If section.option does not exists already, an error is returned.

type Section

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

Section is the config section manager.

func (*Section) Get

func (s *Section) Get(name string) string

Get returns the evalualed (${var} expanded) content for the named option.

func (*Section) GetBool

func (s *Section) GetBool(name string) bool

GetBool returns the bool value for the named option. If option does not exists or if there's any parsing error, false will be returned as default value.

func (*Section) GetInt

func (s *Section) GetInt(name string) int

GetInt returns the int value for the named option. Default value: 0.

func (*Section) GetUint

func (s *Section) GetUint(name string) uint

GetUint returns the uint value for the named option. Default value: 0.

func (*Section) HasOption

func (s *Section) HasOption(name string) bool

HasOption checks if the named option exists in this section.

func (*Section) Name

func (s *Section) Name() string

Name returns section's name.

Directories

Path Synopsis
internal
Package mbcfg implements config cmd util.
Package mbcfg implements config cmd util.
Package profile handles profiled settings.
Package profile handles profiled settings.
Package value holds the maps for the config parser.
Package value holds the maps for the config parser.

Jump to

Keyboard shortcuts

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