Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 431af32

Browse files
authored
package plumbing documentation improvements (#248)
1 parent d0cf207 commit 431af32

File tree

20 files changed

+637
-834
lines changed

20 files changed

+637
-834
lines changed

plumbing/format/config/common.go

+21-19
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@ func New() *Config {
55
return &Config{}
66
}
77

8+
// Config contains all the sections, comments and includes from a config file.
89
type Config struct {
910
Comment *Comment
1011
Sections Sections
1112
Includes Includes
1213
}
1314

15+
// Includes is a list of Includes in a config file.
1416
type Includes []*Include
1517

16-
// A reference to an included configuration.
18+
// Include is a reference to an included config file.
1719
type Include struct {
1820
Path string
1921
Config *Config
2022
}
2123

24+
// Comment string without the prefix '#' or ';'.
2225
type Comment string
2326

2427
const (
28+
// NoSubsection token is passed to Config.Section and Config.SetSection to
29+
// represent the absence of a section.
2530
NoSubsection = ""
2631
)
2732

33+
// Section returns a existing section with the given name or creates a new one.
2834
func (c *Config) Section(name string) *Section {
2935
for i := len(c.Sections) - 1; i >= 0; i-- {
3036
s := c.Sections[i]
@@ -38,36 +44,31 @@ func (c *Config) Section(name string) *Section {
3844
return s
3945
}
4046

41-
// AddOption is a convenience method to add an option to a given
42-
// section and subsection.
43-
//
44-
// Use the NoSubsection constant for the subsection argument
45-
// if no subsection is wanted.
46-
func (s *Config) AddOption(section string, subsection string, key string, value string) *Config {
47+
// AddOption adds an option to a given section and subsection. Use the
48+
// NoSubsection constant for the subsection argument if no subsection is wanted.
49+
func (c *Config) AddOption(section string, subsection string, key string, value string) *Config {
4750
if subsection == "" {
48-
s.Section(section).AddOption(key, value)
51+
c.Section(section).AddOption(key, value)
4952
} else {
50-
s.Section(section).Subsection(subsection).AddOption(key, value)
53+
c.Section(section).Subsection(subsection).AddOption(key, value)
5154
}
5255

53-
return s
56+
return c
5457
}
5558

56-
// SetOption is a convenience method to set an option to a given
57-
// section and subsection.
58-
//
59-
// Use the NoSubsection constant for the subsection argument
60-
// if no subsection is wanted.
61-
func (s *Config) SetOption(section string, subsection string, key string, value string) *Config {
59+
// SetOption sets an option to a given section and subsection. Use the
60+
// NoSubsection constant for the subsection argument if no subsection is wanted.
61+
func (c *Config) SetOption(section string, subsection string, key string, value string) *Config {
6262
if subsection == "" {
63-
s.Section(section).SetOption(key, value)
63+
c.Section(section).SetOption(key, value)
6464
} else {
65-
s.Section(section).Subsection(subsection).SetOption(key, value)
65+
c.Section(section).Subsection(subsection).SetOption(key, value)
6666
}
6767

68-
return s
68+
return c
6969
}
7070

71+
// RemoveSection removes a section from a config file.
7172
func (c *Config) RemoveSection(name string) *Config {
7273
result := Sections{}
7374
for _, s := range c.Sections {
@@ -80,6 +81,7 @@ func (c *Config) RemoveSection(name string) *Config {
8081
return c
8182
}
8283

84+
// RemoveSubsection remove s a subsection from a config file.
8385
func (c *Config) RemoveSubsection(section string, subsection string) *Config {
8486
for _, s := range c.Sections {
8587
if s.IsName(section) {

0 commit comments

Comments
 (0)