config

package
v4.0.0-rc2+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config implements decoding, encoding and manipulation of git config files.

Index

Constants

View Source
const (
	NoSubsection = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment string

type Config

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

func New

func New() *Config

New creates a new config instance.

func (*Config) AddOption

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

AddOption is a convenience method to add an option to a given section and subsection.

Use the NoSubsection constant for the subsection argument if no subsection is wanted.

func (*Config) RemoveSection

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

func (*Config) RemoveSubsection

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

func (*Config) Section

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

func (*Config) SetOption

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

SetOption is a convenience method to set 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 Encoder

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

An Encoder writes config files to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(cfg *Config) error

Encode writes the config in git config format to the stream of the encoder.

type Include

type Include struct {
	Path   string
	Config *Config
}

A reference to a included configuration.

type Includes

type Includes []*Include

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 notmalized.
	Value string
}

func (*Option) IsKey

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

IsKey returns true if the given key matches this options' 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.

type Section

type Section struct {
	Name        string
	Options     Options
	Subsections Subsections
}

func (*Section) AddOption

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

func (*Section) HasSubsection

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

func (*Section) IsName

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

func (*Section) Option

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

func (*Section) RemoveOption

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

func (*Section) SetOption

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

func (*Section) Subsection

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

type Sections

type Sections []*Section

type Subsection

type Subsection struct {
	Name    string
	Options Options
}

func (*Subsection) AddOption

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

func (*Subsection) IsName

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

func (*Subsection) Option

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

func (*Subsection) RemoveOption

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

func (*Subsection) SetOption

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

type Subsections

type Subsections []*Subsection

Jump to

Keyboard shortcuts

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