From 09d2277f0a2345d04091de363cc1c158a2628a8f Mon Sep 17 00:00:00 2001
From: Juan Batiz-Benet <juan@benet.ai>
Date: Mon, 20 Oct 2014 07:35:56 -0700
Subject: [PATCH] f -> run, Function type.

---
 commands/command.go      | 18 ++++++++++++------
 commands/command_test.go | 12 ++++++------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/commands/command.go b/commands/command.go
index c6a2955c..b6d25320 100644
--- a/commands/command.go
+++ b/commands/command.go
@@ -6,11 +6,17 @@ import (
 	"strings"
 )
 
-// Command is an object that defines a command.
+// Function is the type of function that Commands use.
+// It reads from the Request, and writes results to the Response.
+type Function func(*Request, *Response)
+
+// Command is a runnable command, with input arguments and options (flags).
+// It can also have subcommands, to group units of work into sets.
 type Command struct {
-	Help        string
-	Options     []Option
-	f           func(*Request, *Response)
+	Help    string
+	Options []Option
+
+	run         Function
 	subcommands map[string]*Command
 }
 
@@ -51,7 +57,7 @@ func (c *Command) Call(req *Request) *Response {
 	}
 	cmd := cmds[len(cmds)-1]
 
-	if cmd.f == nil {
+	if cmd.run == nil {
 		res.SetError(ErrNotCallable, ErrClient)
 		return res
 	}
@@ -68,7 +74,7 @@ func (c *Command) Call(req *Request) *Response {
 		return res
 	}
 
-	cmd.f(req, res)
+	cmd.run(req, res)
 
 	return res
 }
diff --git a/commands/command_test.go b/commands/command_test.go
index f93bdb71..8e107bca 100644
--- a/commands/command_test.go
+++ b/commands/command_test.go
@@ -8,7 +8,7 @@ func TestOptionValidation(t *testing.T) {
 			Option{[]string{"b", "beep"}, Int},
 			Option{[]string{"B", "boop"}, String},
 		},
-		f: func(req *Request, res *Response) {},
+		run: func(req *Request, res *Response) {},
 	}
 
 	req := NewEmptyRequest()
@@ -84,35 +84,35 @@ func TestRegistration(t *testing.T) {
 			Options: []Option{
 				Option{[]string{"beep"}, Int},
 			},
-			f: func(req *Request, res *Response) {},
+			run: func(req *Request, res *Response) {},
 		},
 
 		&Command{
 			Options: []Option{
 				Option{[]string{"boop"}, Int},
 			},
-			f: func(req *Request, res *Response) {},
+			run: func(req *Request, res *Response) {},
 		},
 
 		&Command{
 			Options: []Option{
 				Option{[]string{"boop"}, String},
 			},
-			f: func(req *Request, res *Response) {},
+			run: func(req *Request, res *Response) {},
 		},
 
 		&Command{
 			Options: []Option{
 				Option{[]string{"bop"}, String},
 			},
-			f: func(req *Request, res *Response) {},
+			run: func(req *Request, res *Response) {},
 		},
 
 		&Command{
 			Options: []Option{
 				Option{[]string{"enc"}, String},
 			},
-			f: func(req *Request, res *Response) {},
+			run: func(req *Request, res *Response) {},
 		},
 	}
 
-- 
GitLab