aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/config/section.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antonio@sourced.tech>2017-02-23 17:07:08 +0100
committerAntonio Jesus Navarro Perez <antonio@sourced.tech>2017-02-23 17:14:43 +0100
commit059a0be78399cdb0648bd514c5b179819d84403d (patch)
tree007fea2e8529b865b354b45c8aed9045e136d462 /plumbing/format/config/section.go
parentb5da4e98571b02dc106de4f9b2cb2a298489f1b1 (diff)
downloadgo-git-059a0be78399cdb0648bd514c5b179819d84403d.tar.gz
plumbing: improve documentation (Fix #242)
Diffstat (limited to 'plumbing/format/config/section.go')
-rw-r--r--plumbing/format/config/section.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/plumbing/format/config/section.go b/plumbing/format/config/section.go
index 1844913..547da1e 100644
--- a/plumbing/format/config/section.go
+++ b/plumbing/format/config/section.go
@@ -2,6 +2,27 @@ package config
import "strings"
+// 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
+//
type Section struct {
Name string
Options Options
@@ -17,29 +38,38 @@ type Sections []*Section
type Subsections []*Subsection
+// IsName checks if the name provided is equals to the Section name, case insensitive.
func (s *Section) IsName(name string) bool {
return strings.ToLower(s.Name) == strings.ToLower(name)
}
+// Option return the value for the specified key. Empty string is returned if
+// key does not exists.
func (s *Section) Option(key string) string {
return s.Options.Get(key)
}
+// AddOption adds a new Option to the Section. The updated Section is returned.
func (s *Section) AddOption(key string, value string) *Section {
s.Options = s.Options.withAddedOption(key, value)
return s
}
+// SetOption adds a new Option to the Section. If the option already exists, is replaced.
+// The updated Section is returned.
func (s *Section) SetOption(key string, value string) *Section {
s.Options = s.Options.withSettedOption(key, value)
return s
}
+// Remove an option with the specified key. The updated Section is returned.
func (s *Section) RemoveOption(key string) *Section {
s.Options = s.Options.withoutOption(key)
return s
}
+// Subsection returns a Subsection from the specified Section. If the
+// Subsection does not exists, new one is created and added to Section.
func (s *Section) Subsection(name string) *Subsection {
for i := len(s.Subsections) - 1; i >= 0; i-- {
ss := s.Subsections[i]
@@ -53,6 +83,7 @@ func (s *Section) Subsection(name string) *Subsection {
return ss
}
+// HasSubsection checks if the Section has a Subsection with the specified name.
func (s *Section) HasSubsection(name string) bool {
for _, ss := range s.Subsections {
if ss.IsName(name) {
@@ -63,24 +94,31 @@ func (s *Section) HasSubsection(name string) bool {
return false
}
+// IsName checks if the name of the subsection is exactly the specified name.
func (s *Subsection) IsName(name string) bool {
return s.Name == name
}
+// Option returns an option with the specified key. If the option does not exists,
+// empty spring will be returned.
func (s *Subsection) Option(key string) string {
return s.Options.Get(key)
}
+// AddOption adds a new Option to the Subsection. The updated Subsection is returned.
func (s *Subsection) AddOption(key string, value string) *Subsection {
s.Options = s.Options.withAddedOption(key, value)
return s
}
+// SetOption adds a new Option to the Subsection. If the option already exists, is replaced.
+// The updated Subsection is returned.
func (s *Subsection) SetOption(key string, value string) *Subsection {
s.Options = s.Options.withSettedOption(key, value)
return s
}
+// RemoveOption removes the option with the specified key. The updated Subsection is returned.
func (s *Subsection) RemoveOption(key string) *Subsection {
s.Options = s.Options.withoutOption(key)
return s