Skip to content

Commit 921b0ad

Browse files
committed
WIP: docs
1 parent d3d15e7 commit 921b0ad

8 files changed

+28
-12
lines changed

chan.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77
)
88

9+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
910
func NewChanResponsePair(req *Request) (ResponseEmitter, Response) {
1011
r := &chanResponse{
1112
req: req,

command.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func (c *Command) call(req *Request, re ResponseEmitter, env Environment) error
173173
return cmd.Run(req, re, env)
174174
}
175175

176-
// Resolve returns the subcommands at the given path
177-
// The returned set of subcommands starts with this command and therefore is always at least size 1
176+
// Resolve returns the subcommands at the given path.
177+
// The returned set of subcommands starts with this command and therefore is always at least size 1.
178178
func (c *Command) Resolve(pth []string) ([]*Command, error) {
179179
cmds := make([]*Command, len(pth)+1)
180180
cmds[0] = c
@@ -233,6 +233,10 @@ func (c *Command) GetOptions(path []string) (map[string]Option, error) {
233233
// DebugValidate checks if the command tree is well-formed.
234234
//
235235
// This operation is slow and should be called from tests only.
236+
//
237+
// TODO: review this; I don't see any reason this needs to be attached to all `Command`s
238+
// rather than being a function which takes in `Command`.
239+
// ValidateCommand(cmd)[]error|<-chan error; called from tests only.
236240
func (c *Command) DebugValidate() map[string][]error {
237241
errs := make(map[string][]error)
238242
var visit func(path string, cm *Command)
@@ -348,6 +352,7 @@ func (c *Command) CheckArguments(req *Request) error {
348352
return nil
349353
}
350354

355+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
351356
type CommandVisitor func(*Command)
352357

353358
// Walks tree of all subcommands (including this one)
@@ -358,6 +363,7 @@ func (c *Command) Walk(visitor CommandVisitor) {
358363
}
359364
}
360365

366+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
361367
func (c *Command) ProcessHelp() {
362368
c.Walk(func(cm *Command) {
363369
ht := &cm.Helptext
@@ -367,6 +373,7 @@ func (c *Command) ProcessHelp() {
367373
})
368374
}
369375

376+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
370377
func ClientError(msg string) error {
371378
return &Error{Code: ErrClient, Message: msg}
372379
}

command_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ func TestEmitterExpectError(t *testing.T) {
374374

375375
switch re.errorCount {
376376
case 0:
377-
t.Errorf("expected SetError to be called")
377+
t.Errorf("expected CloseWithError to be called")
378378
case 1:
379379
default:
380-
t.Errorf("expected SetError to be called once, but was called %d times", re.errorCount)
380+
t.Errorf("expected CloseWithError to be called once, but was called %d times", re.errorCount)
381381
}
382382
}

doc.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
2727
Emitters
2828
29-
30-
3129
An emitter has the Emit method, that takes the command's
3230
function's output as an argument and passes it to the user.
3331
@@ -49,7 +47,6 @@
4947
5048
Responses
5149
52-
5350
A response is a value that the user can read emitted values
5451
from.
5552
@@ -60,16 +57,19 @@
6057
Next() (interface{}, error)
6158
}
6259
60+
TODO: logic pass; docs are several years out of date.
61+
TODO: English pass; <-AME (the whole file needs a pass anyway, so do that).
62+
6363
Responses have a method Next() that returns the next
6464
emitted value and an error value. If the last element has been
6565
received, the returned error value is io.EOF. If the
66-
application code has sent an error using SetError, the error
67-
ErrRcvdError is returned on next, indicating that the caller
68-
should call Error(). Depending on the reponse type, other
69-
errors may also occur.
66+
application's code encounters a fatal error, it will call CloseWithError,
67+
and that the error value will be returned via subsiquent calls to Next().
7068
7169
Pipes
7270
71+
TODO: ^ was this an actual type/interface or was this always an abstract metaphor?
72+
7373
Pipes are pairs (emitter, response), such that a value emitted
7474
on the emitter can be received in the response value. Most
7575
builtin emitters are "pipe" emitters. The most prominent

encoding.go

+5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ var Decoders = map[EncodingType]func(w io.Reader) Decoder{
4949
},
5050
}
5151

52+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
5253
type EncoderFunc func(req *Request) func(w io.Writer) Encoder
54+
55+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
5356
type EncoderMap map[EncodingType]EncoderFunc
5457

5558
var Encoders = EncoderMap{
@@ -67,12 +70,14 @@ var Encoders = EncoderMap{
6770
},
6871
}
6972

73+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
7074
func MakeEncoder(f func(*Request, io.Writer, interface{}) error) func(*Request) func(io.Writer) Encoder {
7175
return func(req *Request) func(io.Writer) Encoder {
7276
return func(w io.Writer) Encoder { return &genericEncoder{f: f, w: w, req: req} }
7377
}
7478
}
7579

80+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
7681
func MakeTypedEncoder(f interface{}) func(*Request) func(io.Writer) Encoder {
7782
val := reflect.ValueOf(f)
7883
t := val.Type()

executor.go

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
)
66

7+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
78
type Executor interface {
89
Execute(req *Request, re ResponseEmitter, env Environment) error
910
}
@@ -22,6 +23,7 @@ type MakeEnvironment func(context.Context, *Request) (Environment, error)
2223
// The user can define a function like this to pass it to cli.Run.
2324
type MakeExecutor func(*Request, interface{}) (Executor, error)
2425

26+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
2527
func NewExecutor(root *Command) Executor {
2628
return &executor{
2729
root: root,

flushfwd.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func (ff *flushfwder) Close() error {
1818
return ff.ResponseEmitter.Close()
1919
}
2020

21+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
2122
func NewFlushForwarder(re ResponseEmitter, f Flusher) ResponseEmitter {
2223
return &flushfwder{ResponseEmitter: re, Flusher: f}
2324
}

responseemitter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type ResponseEmitter interface {
4141
CloseWithError(error) error
4242

4343
// SetLength sets the length of the output
44-
// err is an interface{} so we don't have to manually convert to error.
4544
SetLength(length uint64)
4645

4746
// Emit sends a value.
@@ -71,6 +70,7 @@ func Copy(re ResponseEmitter, res Response) error {
7170
}
7271
}
7372

73+
// TODO: no documentation; [54dbca2b-17f2-42a8-af93-c8d713866138]
7474
func EmitChan(re ResponseEmitter, ch <-chan interface{}) error {
7575
for v := range ch {
7676
err := re.Emit(v)

0 commit comments

Comments
 (0)