summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-11-22 22:18:48 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-11-22 22:18:48 -0500
commit640249036f58f79493c9c995f337fc9a2c67c6cb (patch)
treeeec6ade0cde6b41d2626f777a1f1d312330b279b
parentc4e844f390aaeabfc3ffe4e28457c8d0c84e934e (diff)
use an interface to avoid specifying *textproto.FIWriter everywhere
-rw-r--r--cmd.go11
-rw-r--r--cmd_command.go24
-rw-r--r--cmd_comment.go8
-rw-r--r--cmd_commit.go16
-rw-r--r--ez.go4
5 files changed, 31 insertions, 32 deletions
diff --git a/cmd.go b/cmd.go
index 5e76708..4d56ad8 100644
--- a/cmd.go
+++ b/cmd.go
@@ -1,14 +1,15 @@
package libfastimport
-import (
- "git.lukeshu.com/go/libfastimport/textproto"
-)
-
type fiReader interface {
PeekLine() (string, error)
ReadLine() (string, error)
}
+type fiWriter interface {
+ WriteData(string) error
+ WriteLine(a ...interface{}) error
+}
+
type cmdClass int
const (
@@ -20,6 +21,6 @@ const (
type Cmd interface {
fiCmdRead(fiReader) (Cmd, error)
- fiCmdWrite(*textproto.FIWriter) error
+ fiCmdWrite(fiWriter) error
fiCmdClass() cmdClass
}
diff --git a/cmd_command.go b/cmd_command.go
index b438cb6..c6e7080 100644
--- a/cmd_command.go
+++ b/cmd_command.go
@@ -21,7 +21,7 @@ type CmdCommit struct {
}
func (c CmdCommit) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdCommit) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdCommit) fiCmdWrite(fiw fiWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("commit", c.Ref)
@@ -90,9 +90,9 @@ func (CmdCommit) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
type CmdCommitEnd struct{}
-func (CmdCommitEnd) fiCmdClass() cmdClass { return cmdClassCommit }
-func (CmdCommitEnd) fiCmdWrite(fiw *textproto.FIWriter) error { return nil }
-func (CmdCommitEnd) fiCmdRead(fir fiReader) (Cmd, error) { panic("not reached") }
+func (CmdCommitEnd) fiCmdClass() cmdClass { return cmdClassCommit }
+func (CmdCommitEnd) fiCmdWrite(fiw fiWriter) error { return nil }
+func (CmdCommitEnd) fiCmdRead(fir fiReader) (Cmd, error) { panic("not reached") }
// tag /////////////////////////////////////////////////////////////////////////
@@ -104,7 +104,7 @@ type CmdTag struct {
}
func (c CmdTag) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdTag) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdTag) fiCmdWrite(fiw fiWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("tag", c.RefName)
@@ -151,7 +151,7 @@ type CmdReset struct {
}
func (c CmdReset) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdReset) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdReset) fiCmdWrite(fiw fiWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("reset", c.RefName)
@@ -186,7 +186,7 @@ type CmdBlob struct {
}
func (c CmdBlob) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdBlob) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdBlob) fiCmdWrite(fiw fiWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("blob")
@@ -224,7 +224,7 @@ func (CmdBlob) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
type CmdCheckpoint struct{}
func (c CmdCheckpoint) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdCheckpoint) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdCheckpoint) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("checkpoint")
}
func init() { parser_registerCmd("checkpoint\n", CmdCheckpoint{}) }
@@ -243,7 +243,7 @@ type CmdProgress struct {
}
func (c CmdProgress) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdProgress) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdProgress) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("progress", c.Str)
}
func init() { parser_registerCmd("progress ", CmdProgress{}) }
@@ -263,7 +263,7 @@ type CmdFeature struct {
}
func (c CmdFeature) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdFeature) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdFeature) fiCmdWrite(fiw fiWriter) error {
if c.Argument != "" {
return fiw.WriteLine("feature", c.Feature+"="+c.Argument)
} else {
@@ -296,7 +296,7 @@ type CmdOption struct {
}
func (c CmdOption) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdOption) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdOption) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("option", c.Option)
}
func init() { parser_registerCmd("option ", CmdOption{}) }
@@ -314,7 +314,7 @@ func (CmdOption) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
type CmdDone struct{}
func (c CmdDone) fiCmdClass() cmdClass { return cmdClassCommand }
-func (c CmdDone) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdDone) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("done")
}
func init() { parser_registerCmd("done\n", CmdDone{}) }
diff --git a/cmd_comment.go b/cmd_comment.go
index 6ce801c..d2aaccc 100644
--- a/cmd_comment.go
+++ b/cmd_comment.go
@@ -15,7 +15,7 @@ type CmdComment struct {
}
func (c CmdComment) fiCmdClass() cmdClass { return cmdClassComment }
-func (c CmdComment) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdComment) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("#" + c.Comment)
}
func init() { parser_registerCmd("#", CmdComment{}) }
@@ -34,7 +34,7 @@ type CmdGetMark struct {
}
func (c CmdGetMark) fiCmdClass() cmdClass { return cmdClassComment }
-func (c CmdGetMark) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdGetMark) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("get-mark", ":"+strconv.Itoa(c.Mark))
}
func init() { parser_registerCmd("get-mark :", CmdGetMark{}) }
@@ -58,7 +58,7 @@ type CmdCatBlob struct {
}
func (c CmdCatBlob) fiCmdClass() cmdClass { return cmdClassComment }
-func (c CmdCatBlob) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdCatBlob) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("cat-blob", c.DataRef)
}
func init() { parser_registerCmd("cat-blob ", CmdCatBlob{}) }
@@ -91,7 +91,7 @@ func (c CmdLs) fiCmdClass() cmdClass {
}
return cmdClassComment
}
-func (c CmdLs) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (c CmdLs) fiCmdWrite(fiw fiWriter) error {
if c.DataRef == "" {
return fiw.WriteLine("ls", c.Path)
} else {
diff --git a/cmd_commit.go b/cmd_commit.go
index a5dcb90..b108158 100644
--- a/cmd_commit.go
+++ b/cmd_commit.go
@@ -17,7 +17,7 @@ type FileModify struct {
}
func (o FileModify) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o FileModify) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o FileModify) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("M", o.Mode, o.DataRef, o.Path)
}
func init() { parser_registerCmd("M ", FileModify{}) }
@@ -69,7 +69,7 @@ type FileModifyInline struct {
}
func (o FileModifyInline) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o FileModifyInline) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o FileModifyInline) fiCmdWrite(fiw fiWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("M", o.Mode, "inline", o.Path)
ez.WriteData(o.Data)
@@ -84,7 +84,7 @@ type FileDelete struct {
}
func (o FileDelete) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o FileDelete) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o FileDelete) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("D", o.Path)
}
func init() { parser_registerCmd("D ", FileDelete{}) }
@@ -104,7 +104,7 @@ type FileCopy struct {
}
func (o FileCopy) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o FileCopy) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o FileCopy) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("C", o.Src, o.Dst)
}
func init() { parser_registerCmd("C ", FileDelete{}) }
@@ -121,7 +121,7 @@ type FileRename struct {
}
func (o FileRename) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o FileRename) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o FileRename) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("R", o.Src, o.Dst)
}
func init() { parser_registerCmd("R ", FileDelete{}) }
@@ -135,7 +135,7 @@ func (FileRename) fiCmdRead(fir fiReader) (cmd Cmd, err error) {
type FileDeleteAll struct{}
func (o FileDeleteAll) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o FileDeleteAll) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o FileDeleteAll) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("deleteall")
}
func init() { parser_registerCmd("deleteall\n", FileDeleteAll{}) }
@@ -155,7 +155,7 @@ type NoteModify struct {
}
func (o NoteModify) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o NoteModify) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o NoteModify) fiCmdWrite(fiw fiWriter) error {
return fiw.WriteLine("N", o.DataRef, o.CommitIsh)
}
func init() { parser_registerCmd("N ", NoteModify{}) }
@@ -199,7 +199,7 @@ type NoteModifyInline struct {
}
func (o NoteModifyInline) fiCmdClass() cmdClass { return cmdClassCommit }
-func (o NoteModifyInline) fiCmdWrite(fiw *textproto.FIWriter) error {
+func (o NoteModifyInline) fiCmdWrite(fiw fiWriter) error {
ez := &ezfiw{fiw: fiw}
ez.WriteLine("N", "inline", o.CommitIsh)
ez.WriteData(o.Data)
diff --git a/ez.go b/ez.go
index 4c220b5..eca3494 100644
--- a/ez.go
+++ b/ez.go
@@ -2,12 +2,10 @@ package libfastimport
import (
"strconv"
-
- "git.lukeshu.com/go/libfastimport/textproto"
)
type ezfiw struct {
- fiw *textproto.FIWriter
+ fiw fiWriter
err error
}