aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/config/section.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/section.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/section.go')
-rw-r--r--plumbing/format/config/section.go85
1 files changed, 60 insertions, 25 deletions
diff --git a/plumbing/format/config/section.go b/plumbing/format/config/section.go
index f743da6..07f72f3 100644
--- a/plumbing/format/config/section.go
+++ b/plumbing/format/config/section.go
@@ -64,31 +64,6 @@ func (s *Section) IsName(name string) bool {
return strings.EqualFold(s.Name, 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 {
@@ -115,6 +90,55 @@ func (s *Section) HasSubsection(name string) bool {
return false
}
+// RemoveSubsection removes a subsection from a Section.
+func (s *Section) RemoveSubsection(name string) *Section {
+ result := Subsections{}
+ for _, s := range s.Subsections {
+ if !s.IsName(name) {
+ result = append(result, s)
+ }
+ }
+
+ s.Subsections = result
+ return s
+}
+
+// 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)
+}
+
+// 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 (s *Section) OptionAll(key string) []string {
+ return s.Options.GetAll(key)
+}
+
+// HasOption checks if the Section has an Option with the given key.
+func (s *Section) HasOption(key string) bool {
+ return s.Options.Has(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
+}
+
// IsName checks if the name of the subsection is exactly the specified name.
func (s *Subsection) IsName(name string) bool {
return s.Name == name
@@ -126,6 +150,17 @@ func (s *Subsection) Option(key string) string {
return s.Options.Get(key)
}
+// 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 (s *Subsection) OptionAll(key string) []string {
+ return s.Options.GetAll(key)
+}
+
+// HasOption checks if the Subsection has an Option with the given key.
+func (s *Subsection) HasOption(key string) bool {
+ return s.Options.Has(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)