config

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoSubsection token is passed to Config.Section and Config.SetSection to
	// represent the absence of a section.
	NoSubsection = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment string

Comment string without the prefix '#' or ';'.

type Config

type Config struct {
	Comment  *Comment
	Sections Sections
	Includes Includes
}

Config contains all the sections, comments and includes from a config file.

func BareDecode

func BareDecode(repoPath string) (*Config, error)

func New

func New() *Config

New creates a new config instance.

func (*Config) AddOption

func (c *Config) AddOption(section string, subsection string, key string, value string) *Config

AddOption adds an option to a given section and subsection. Use the NoSubsection constant for the subsection argument if no subsection is wanted.

func (*Config) HasSection

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

HasSection checks if the Config has a section with the specified name.

func (*Config) HashAlgo

func (c *Config) HashAlgo() string

func (*Config) RemoveSection

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

RemoveSection removes a section from a config file.

func (*Config) RemoveSubsection

func (c *Config) RemoveSubsection(section string, subsection string) *Config

RemoveSubsection remove a subsection from a config file.

func (*Config) Section

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

Section returns a existing section with the given name or creates a new one.

func (*Config) SetOption

func (c *Config) SetOption(section string, subsection string, key string, value string) *Config

SetOption sets an option to a given section and subsection. Use the NoSubsection constant for the subsection argument if no subsection is wanted.

type Decoder

type Decoder struct {
	io.Reader
}

A Decoder reads and decodes config files from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

func (d *Decoder) Decode(config *Config) error

Decode reads the whole config from its input and stores it in the value pointed to by config.

type Include

type Include struct {
	Path   string
	Config *Config
}

Include is a reference to an included config file.

type Includes

type Includes []*Include

Includes is a list of Includes in a config file.

type Option

type Option struct {
	// Key preserving original caseness.
	// Use IsKey instead to compare key regardless of caseness.
	Key string
	// Original value as string, could be not normalized.
	Value string
}

Option defines a key/value entity in a config file.

func (*Option) IsKey

func (o *Option) IsKey(key string) bool

IsKey returns true if the given key matches this option's key in a case-insensitive comparison.

type Options

type Options []*Option

func (Options) Get

func (opts Options) Get(key string) string

Get gets the value for the given key if set, otherwise it returns the empty string.

Note that there is no difference

This matches git behaviour since git v1.8.1-rc1, if there are multiple definitions of a key, the last one wins.

See: http://article.gmane.org/gmane.linux.kernel/1407184

In order to get all possible values for the same key, use GetAll.

func (Options) GetAll

func (opts Options) GetAll(key string) []string

GetAll returns all possible values for the same key.

func (Options) GoString

func (opts Options) GoString() string

func (Options) Has

func (opts Options) Has(key string) bool

Has checks if an Option exist with the given key.

type Section

type Section struct {
	Name        string
	Options     Options
	Subsections Subsections
}

Section is the representation of a section inside git configuration files. Each Section contains Options that are used by both the Git plumbing and the porcelains. Sections can be further divided into subsections. To begin a subsection put its name in double quotes, separated by space from the section name, in the section header, like in the example below:

[section "subsection"]

All the other lines (and the remainder of the line after the section header) are recognized as option variables, in the form "name = value" (or just name, which is a short-hand to say that the variable is the boolean "true"). The variable names are case-insensitive, allow only alphanumeric characters and -, and must start with an alphabetic character:

[section "subsection1"]
    option1 = value1
    option2
[section "subsection2"]
    option3 = value2

func (*Section) AddOption

func (s *Section) AddOption(key string, value string) *Section

AddOption adds a new Option to the Section. The updated Section is returned.

func (*Section) HasOption

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

HasOption checks if the Section has an Option with the given key.

func (*Section) HasSubsection

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

HasSubsection checks if the Section has a Subsection with the specified name.

func (*Section) IsName

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

IsName checks if the name provided is equals to the Section name, case insensitive.

func (*Section) Option

func (s *Section) Option(key string) string

Option returns the value for the specified key. Empty string is returned if key does not exists.

func (*Section) OptionAll

func (s *Section) OptionAll(key string) []string

OptionAll returns all possible values for an option with the specified key. If the option does not exists, an empty slice will be returned.

func (*Section) RemoveOption

func (s *Section) RemoveOption(key string) *Section

Remove an option with the specified key. The updated Section is returned.

func (*Section) RemoveSubsection

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

RemoveSubsection removes a subsection from a Section.

func (*Section) SetOption

func (s *Section) SetOption(key string, value string) *Section

SetOption adds a new Option to the Section. If the option already exists, is replaced. The updated Section is returned.

func (*Section) Subsection

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

Subsection returns a Subsection from the specified Section. If the Subsection does not exists, new one is created and added to Section.

type Sections

type Sections []*Section

func (Sections) GoString

func (s Sections) GoString() string

type Subsection

type Subsection struct {
	Name    string
	Options Options
}

func (*Subsection) AddOption

func (s *Subsection) AddOption(key string, value string) *Subsection

AddOption adds a new Option to the Subsection. The updated Subsection is returned.

func (*Subsection) HasOption

func (s *Subsection) HasOption(key string) bool

HasOption checks if the Subsection has an Option with the given key.

func (*Subsection) IsName

func (s *Subsection) IsName(name string) bool

IsName checks if the name of the subsection is exactly the specified name.

func (*Subsection) Option

func (s *Subsection) Option(key string) string

Option returns an option with the specified key. If the option does not exists, empty spring will be returned.

func (*Subsection) OptionAll

func (s *Subsection) OptionAll(key string) []string

OptionAll returns all possible values for an option with the specified key. If the option does not exists, an empty slice will be returned.

func (*Subsection) RemoveOption

func (s *Subsection) RemoveOption(key string) *Subsection

RemoveOption removes the option with the specified key. The updated Subsection is returned.

func (*Subsection) SetOption

func (s *Subsection) SetOption(key string, value ...string) *Subsection

SetOption adds a new Option to the Subsection. If the option already exists, is replaced. The updated Subsection is returned.

type Subsections

type Subsections []*Subsection

func (Subsections) GoString

func (s Subsections) GoString() string

Jump to

Keyboard shortcuts

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