aboutsummaryrefslogtreecommitdiff
path: root/lib/ssh/config/pattern.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ssh/config/pattern.go')
-rw-r--r--lib/ssh/config/pattern.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/ssh/config/pattern.go b/lib/ssh/config/pattern.go
index d413fc9a..39199fd8 100644
--- a/lib/ssh/config/pattern.go
+++ b/lib/ssh/config/pattern.go
@@ -4,7 +4,11 @@
package config
-import "path/filepath"
+import (
+ "bytes"
+ "io"
+ "path/filepath"
+)
type pattern struct {
value string
@@ -22,6 +26,28 @@ func newPattern(s string) (pat *pattern) {
return pat
}
+// MarshalText encode the pattern back to ssh_config format.
+func (pat *pattern) MarshalText() (text []byte, err error) {
+ var buf bytes.Buffer
+
+ if pat.isNegate {
+ buf.WriteByte('!')
+ }
+ buf.WriteString(pat.value)
+
+ return buf.Bytes(), nil
+}
+
+// WriteTo marshal the pattern into text and write it to w.
+func (pat *pattern) WriteTo(w io.Writer) (n int64, err error) {
+ var text []byte
+ text, _ = pat.MarshalText()
+
+ var c int
+ c, err = w.Write(text)
+ return int64(c), err
+}
+
// isMatch will return true if input string match with regex and isNegate is
// false; otherwise it will return false.
func (pat *pattern) isMatch(s string) bool {