aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/config/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-10-09 11:47:52 +0200
committerGitHub <noreply@github.com>2020-10-09 11:47:52 +0200
commitb5b59f5fc9f9c0cd3ad1329c814b6a0d8126e675 (patch)
tree8e4aca9bf78a24e0c691e0bb4a478a0e5ca5e4ba /plumbing/format/config/common.go
parent63d92533b538cb380667deee5dc6d32f0946c737 (diff)
parentb40ca794fe33a28f1ca4d6aedacc76b706ea8b04 (diff)
downloadgo-git-b5b59f5fc9f9c0cd3ad1329c814b6a0d8126e675.tar.gz
Merge pull request #112 from MichaelMure/complete-config
config: add missing functions for completeness
Diffstat (limited to 'plumbing/format/config/common.go')
-rw-r--r--plumbing/format/config/common.go54
1 files changed, 32 insertions, 22 deletions
diff --git a/plumbing/format/config/common.go b/plumbing/format/config/common.go
index 8f98ad1..6d689ea 100644
--- a/plumbing/format/config/common.go
+++ b/plumbing/format/config/common.go
@@ -44,28 +44,14 @@ func (c *Config) Section(name string) *Section {
return s
}
-// AddOption adds an option to a given section and subsection. Use the
-// NoSubsection constant for the subsection argument if no subsection is wanted.
-func (c *Config) AddOption(section string, subsection string, key string, value string) *Config {
- if subsection == "" {
- c.Section(section).AddOption(key, value)
- } else {
- c.Section(section).Subsection(subsection).AddOption(key, value)
- }
-
- return c
-}
-
-// SetOption sets an option to a given section and subsection. Use the
-// NoSubsection constant for the subsection argument if no subsection is wanted.
-func (c *Config) SetOption(section string, subsection string, key string, value string) *Config {
- if subsection == "" {
- c.Section(section).SetOption(key, value)
- } else {
- c.Section(section).Subsection(subsection).SetOption(key, value)
+// HasSection checks if the Config has a section with the specified name.
+func (c *Config) HasSection(name string) bool {
+ for _, s := range c.Sections {
+ if s.IsName(name) {
+ return true
+ }
}
-
- return c
+ return false
}
// RemoveSection removes a section from a config file.
@@ -81,7 +67,7 @@ func (c *Config) RemoveSection(name string) *Config {
return c
}
-// RemoveSubsection remove s a subsection from a config file.
+// RemoveSubsection remove a subsection from a config file.
func (c *Config) RemoveSubsection(section string, subsection string) *Config {
for _, s := range c.Sections {
if s.IsName(section) {
@@ -97,3 +83,27 @@ func (c *Config) RemoveSubsection(section string, subsection string) *Config {
return c
}
+
+// AddOption adds an option to a given section and subsection. Use the
+// NoSubsection constant for the subsection argument if no subsection is wanted.
+func (c *Config) AddOption(section string, subsection string, key string, value string) *Config {
+ if subsection == "" {
+ c.Section(section).AddOption(key, value)
+ } else {
+ c.Section(section).Subsection(subsection).AddOption(key, value)
+ }
+
+ return c
+}
+
+// SetOption sets an option to a given section and subsection. Use the
+// NoSubsection constant for the subsection argument if no subsection is wanted.
+func (c *Config) SetOption(section string, subsection string, key string, value string) *Config {
+ if subsection == "" {
+ c.Section(section).SetOption(key, value)
+ } else {
+ c.Section(section).Subsection(subsection).SetOption(key, value)
+ }
+
+ return c
+}