aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/config
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-07-27 17:16:34 +0200
committerSantiago M. Mola <santi@mola.io>2017-08-01 13:01:59 +0200
commit1e70916ca7e4d5c0ad00edbfd1877e06d7587fc6 (patch)
tree2221ddc6b599ae042b4ee371a6e4b2cad08fbff6 /plumbing/format/config
parent9488c59834f6a2591910b7b360721cec2c16c548 (diff)
downloadgo-git-1e70916ca7e4d5c0ad00edbfd1877e06d7587fc6.tar.gz
format/config: add GoString
This is more convenient for testing and debugging.
Diffstat (limited to 'plumbing/format/config')
-rw-r--r--plumbing/format/config/option.go10
-rw-r--r--plumbing/format/config/section.go23
2 files changed, 32 insertions, 1 deletions
diff --git a/plumbing/format/config/option.go b/plumbing/format/config/option.go
index 3c391c6..481af02 100644
--- a/plumbing/format/config/option.go
+++ b/plumbing/format/config/option.go
@@ -1,6 +1,7 @@
package config
import (
+ "fmt"
"strings"
)
@@ -21,6 +22,15 @@ func (o *Option) IsKey(key string) bool {
return strings.ToLower(o.Key) == strings.ToLower(key)
}
+func (opts Options) GoString() string {
+ var strs []string
+ for _, opt := range opts {
+ strs = append(strs, fmt.Sprintf("%#v", opt))
+ }
+
+ return strings.Join(strs, ", ")
+}
+
// Get gets the value for the given key if set,
// otherwise it returns the empty string.
//
diff --git a/plumbing/format/config/section.go b/plumbing/format/config/section.go
index 547da1e..eeefe84 100644
--- a/plumbing/format/config/section.go
+++ b/plumbing/format/config/section.go
@@ -1,6 +1,9 @@
package config
-import "strings"
+import (
+ "fmt"
+ "strings"
+)
// Section is the representation of a section inside git configuration files.
// Each Section contains Options that are used by both the Git plumbing
@@ -36,8 +39,26 @@ type Subsection struct {
type Sections []*Section
+func (s Sections) GoString() string {
+ var strs []string
+ for _, ss := range s {
+ strs = append(strs, fmt.Sprintf("%#v", ss))
+ }
+
+ return strings.Join(strs, ", ")
+}
+
type Subsections []*Subsection
+func (s Subsections) GoString() string {
+ var strs []string
+ for _, ss := range s {
+ strs = append(strs, fmt.Sprintf("%#v", ss))
+ }
+
+ return strings.Join(strs, ", ")
+}
+
// 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)