Skip to content

Commit 746d639

Browse files
committed
cmdkit: finish merge
1 parent 9ac2806 commit 746d639

33 files changed

+177
-213
lines changed

argument.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmdkit
1+
package cmds
22

33
type ArgumentType int
44

chan.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"io"
66
"sync"
7-
8-
"github.com/ipfs/go-ipfs-cmdkit"
97
)
108

119
func NewChanResponsePair(req *Request) (ResponseEmitter, Response) {
@@ -63,18 +61,18 @@ func (r *chanResponse) Request() *Request {
6361
return r.req
6462
}
6563

66-
func (r *chanResponse) Error() *cmdkit.Error {
64+
func (r *chanResponse) Error() *Error {
6765
select {
6866
case <-r.closeCh:
6967
if r.err == nil || r.err == io.EOF {
7068
return nil
7169
}
7270

73-
if e, ok := r.err.(*cmdkit.Error); ok {
71+
if e, ok := r.err.(*Error); ok {
7472
return e
7573
}
7674

77-
return &cmdkit.Error{Message: r.err.Error()}
75+
return &Error{Message: r.err.Error()}
7876
default:
7977
return nil
8078
}
@@ -194,7 +192,7 @@ func (re *chanResponseEmitter) closeWithError(err error) {
194192
err = io.EOF
195193
}
196194

197-
if e, ok := err.(cmdkit.Error); ok {
195+
if e, ok := err.(Error); ok {
198196
err = &e
199197
}
200198

cli/helptext.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
"text/template"
1010

11-
"github.com/ipfs/go-ipfs-cmdkit"
1211
"github.com/ipfs/go-ipfs-cmds"
1312
)
1413

@@ -252,13 +251,13 @@ func generateSynopsis(cmd *cmds.Command, path string) string {
252251
if len(n) > 1 {
253252
pre = "--"
254253
}
255-
if opt.Type() == cmdkit.Bool && opt.Default() == true {
254+
if opt.Type() == cmds.Bool && opt.Default() == true {
256255
pre = "--"
257256
sopt = fmt.Sprintf("%s%s=false", pre, n)
258257
break
259258
} else {
260259
if i == 0 {
261-
if opt.Type() == cmdkit.Bool {
260+
if opt.Type() == cmds.Bool {
262261
sopt = fmt.Sprintf("%s%s", pre, n)
263262
} else {
264263
sopt = fmt.Sprintf("%s%s=<%s>", pre, n, valopt)
@@ -311,7 +310,7 @@ func optionFlag(flag string) string {
311310

312311
func optionText(cmd ...*cmds.Command) []string {
313312
// get a slice of the options we want to list out
314-
options := make([]cmdkit.Option, 0)
313+
options := make([]cmds.Option, 0)
315314
for _, c := range cmd {
316315
for _, opt := range c.Options {
317316
options = append(options, opt)
@@ -411,7 +410,7 @@ func usageText(cmd *cmds.Command) string {
411410
return s
412411
}
413412

414-
func argUsageText(arg cmdkit.Argument) string {
413+
func argUsageText(arg cmds.Argument) string {
415414
s := arg.Name
416415

417416
if arg.Required {

cli/helptext_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import (
44
"strings"
55
"testing"
66

7-
"github.com/ipfs/go-ipfs-cmdkit"
87
"github.com/ipfs/go-ipfs-cmds"
98
)
109

1110
func TestSynopsisGenerator(t *testing.T) {
1211
command := &cmds.Command{
13-
Arguments: []cmdkit.Argument{
14-
cmdkit.StringArg("required", true, false, ""),
15-
cmdkit.StringArg("variadic", false, true, ""),
12+
Arguments: []cmds.Argument{
13+
cmds.StringArg("required", true, false, ""),
14+
cmds.StringArg("variadic", false, true, ""),
1615
},
17-
Options: []cmdkit.Option{
18-
cmdkit.StringOption("opt", "o", "Option"),
16+
Options: []cmds.Option{
17+
cmds.StringOption("opt", "o", "Option"),
1918
},
20-
Helptext: cmdkit.HelpText{
19+
Helptext: cmds.HelpText{
2120
SynopsisOptionsValues: map[string]string{
2221
"opt": "OPTION",
2322
},

cli/parse.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import (
1010
"path/filepath"
1111
"strings"
1212

13-
"github.com/ipfs/go-ipfs-cmds"
14-
1513
osh "github.com/Kubuxu/go-os-helper"
16-
"github.com/ipfs/go-ipfs-cmdkit"
14+
"github.com/ipfs/go-ipfs-cmds"
1715
"github.com/ipfs/go-ipfs-files"
1816
logging "github.com/ipfs/go-log"
1917
)
@@ -101,7 +99,7 @@ func parse(req *cmds.Request, cmdline []string, root *cmds.Command) (err error)
10199
var (
102100
path = make([]string, 0, len(cmdline))
103101
args = make([]string, 0, len(cmdline))
104-
opts = cmdkit.OptMap{}
102+
opts = cmds.OptMap{}
105103
cmd = root
106104
)
107105

@@ -246,7 +244,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
246244

247245
fillingVariadic := iArgDef+1 > len(argDefs)
248246
switch argDef.Type {
249-
case cmdkit.ArgString:
247+
case cmds.ArgString:
250248
if len(inputs) > 0 {
251249
stringArgs, inputs = append(stringArgs, inputs[0]), inputs[1:]
252250
} else if stdin != nil && argDef.SupportsStdin && !fillingVariadic {
@@ -258,7 +256,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
258256
stdin = nil
259257
}
260258
}
261-
case cmdkit.ArgFile:
259+
case cmds.ArgFile:
262260
if len(inputs) > 0 {
263261
// treat stringArg values as file paths
264262
fpath := inputs[0]
@@ -390,7 +388,7 @@ func splitkv(opt string) (k, v string, ok bool) {
390388
}
391389
}
392390

393-
func parseOpt(opt, value string, opts map[string]cmdkit.Option) (interface{}, error) {
391+
func parseOpt(opt, value string, opts map[string]cmds.Option) (interface{}, error) {
394392
optDef, ok := opts[opt]
395393
if !ok {
396394
return nil, fmt.Errorf("unknown option %q", opt)
@@ -408,7 +406,7 @@ type kv struct {
408406
Value interface{}
409407
}
410408

411-
func (st *parseState) parseShortOpts(optDefs map[string]cmdkit.Option) ([]kv, error) {
409+
func (st *parseState) parseShortOpts(optDefs map[string]cmds.Option) ([]kv, error) {
412410
k, vStr, ok := splitkv(st.cmdline[st.i][1:])
413411
kvs := make([]kv, 0, len(k))
414412

@@ -431,7 +429,7 @@ func (st *parseState) parseShortOpts(optDefs map[string]cmdkit.Option) ([]kv, er
431429
case !ok:
432430
return nil, fmt.Errorf("unknown option %q", k)
433431

434-
case od.Type() == cmdkit.Bool:
432+
case od.Type() == cmds.Bool:
435433
// single char flags for bools
436434
kvs = append(kvs, kv{
437435
Key: flag,
@@ -471,14 +469,14 @@ func (st *parseState) parseShortOpts(optDefs map[string]cmdkit.Option) ([]kv, er
471469
return kvs, nil
472470
}
473471

474-
func (st *parseState) parseLongOpt(optDefs map[string]cmdkit.Option) (string, interface{}, error) {
472+
func (st *parseState) parseLongOpt(optDefs map[string]cmds.Option) (string, interface{}, error) {
475473
k, v, ok := splitkv(st.peek()[2:])
476474
if !ok {
477475
optDef, ok := optDefs[k]
478476
if !ok {
479477
return "", nil, fmt.Errorf("unknown option %q", k)
480478
}
481-
if optDef.Type() == cmdkit.Bool {
479+
if optDef.Type() == cmds.Bool {
482480
return k, true, nil
483481
} else if st.i < len(st.cmdline)-1 {
484482
st.i++
@@ -492,7 +490,7 @@ func (st *parseState) parseLongOpt(optDefs map[string]cmdkit.Option) (string, in
492490
return k, optval, err
493491
}
494492

495-
func getArgDef(i int, argDefs []cmdkit.Argument) *cmdkit.Argument {
493+
func getArgDef(i int, argDefs []cmds.Argument) *cmds.Argument {
496494
if i < len(argDefs) {
497495
// get the argument definition (usually just argDefs[i])
498496
return &argDefs[i]
@@ -509,7 +507,7 @@ func getArgDef(i int, argDefs []cmdkit.Argument) *cmdkit.Argument {
509507
const notRecursiveFmtStr = "'%s' is a directory, use the '-%s' flag to specify directories"
510508
const dirNotSupportedFmtStr = "invalid path '%s', argument '%s' does not support directories"
511509

512-
func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden bool) (files.Node, error) {
510+
func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (files.Node, error) {
513511
stat, err := os.Lstat(fpath)
514512
if err != nil {
515513
return nil, err

cli/parse_test.go

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
cmdkit "github.com/ipfs/go-ipfs-cmdkit"
1413
cmds "github.com/ipfs/go-ipfs-cmds"
1514
)
1615

@@ -70,15 +69,15 @@ func TestSameWords(t *testing.T) {
7069

7170
func TestOptionParsing(t *testing.T) {
7271
cmd := &cmds.Command{
73-
Options: []cmdkit.Option{
74-
cmdkit.StringOption("string", "s", "a string"),
75-
cmdkit.BoolOption("bool", "b", "a bool"),
72+
Options: []cmds.Option{
73+
cmds.StringOption("string", "s", "a string"),
74+
cmds.BoolOption("bool", "b", "a bool"),
7675
},
7776
Subcommands: map[string]*cmds.Command{
7877
"test": &cmds.Command{},
7978
"defaults": &cmds.Command{
80-
Options: []cmdkit.Option{
81-
cmdkit.StringOption("opt", "o", "an option").WithDefault("def"),
79+
Options: []cmds.Option{
80+
cmds.StringOption("opt", "o", "an option").WithDefault("def"),
8281
},
8382
},
8483
},
@@ -158,36 +157,36 @@ func TestArgumentParsing(t *testing.T) {
158157
Subcommands: map[string]*cmds.Command{
159158
"noarg": {},
160159
"onearg": {
161-
Arguments: []cmdkit.Argument{
162-
cmdkit.StringArg("a", true, false, "some arg"),
160+
Arguments: []cmds.Argument{
161+
cmds.StringArg("a", true, false, "some arg"),
163162
},
164163
},
165164
"twoargs": {
166-
Arguments: []cmdkit.Argument{
167-
cmdkit.StringArg("a", true, false, "some arg"),
168-
cmdkit.StringArg("b", true, false, "another arg"),
165+
Arguments: []cmds.Argument{
166+
cmds.StringArg("a", true, false, "some arg"),
167+
cmds.StringArg("b", true, false, "another arg"),
169168
},
170169
},
171170
"variadic": {
172-
Arguments: []cmdkit.Argument{
173-
cmdkit.StringArg("a", true, true, "some arg"),
171+
Arguments: []cmds.Argument{
172+
cmds.StringArg("a", true, true, "some arg"),
174173
},
175174
},
176175
"optional": {
177-
Arguments: []cmdkit.Argument{
178-
cmdkit.StringArg("b", false, true, "another arg"),
176+
Arguments: []cmds.Argument{
177+
cmds.StringArg("b", false, true, "another arg"),
179178
},
180179
},
181180
"optionalsecond": {
182-
Arguments: []cmdkit.Argument{
183-
cmdkit.StringArg("a", true, false, "some arg"),
184-
cmdkit.StringArg("b", false, false, "another arg"),
181+
Arguments: []cmds.Argument{
182+
cmds.StringArg("a", true, false, "some arg"),
183+
cmds.StringArg("b", false, false, "another arg"),
185184
},
186185
},
187186
"reversedoptional": {
188-
Arguments: []cmdkit.Argument{
189-
cmdkit.StringArg("a", false, false, "some arg"),
190-
cmdkit.StringArg("b", true, false, "another arg"),
187+
Arguments: []cmds.Argument{
188+
cmds.StringArg("a", false, false, "some arg"),
189+
cmds.StringArg("b", true, false, "another arg"),
191190
},
192191
},
193192
},
@@ -264,43 +263,43 @@ func TestBodyArgs(t *testing.T) {
264263
Subcommands: map[string]*cmds.Command{
265264
"noarg": {},
266265
"stdinenabled": {
267-
Arguments: []cmdkit.Argument{
268-
cmdkit.StringArg("a", true, true, "some arg").EnableStdin(),
266+
Arguments: []cmds.Argument{
267+
cmds.StringArg("a", true, true, "some arg").EnableStdin(),
269268
},
270269
},
271270
"stdinenabled2args": &cmds.Command{
272-
Arguments: []cmdkit.Argument{
273-
cmdkit.StringArg("a", true, false, "some arg"),
274-
cmdkit.StringArg("b", true, true, "another arg").EnableStdin(),
271+
Arguments: []cmds.Argument{
272+
cmds.StringArg("a", true, false, "some arg"),
273+
cmds.StringArg("b", true, true, "another arg").EnableStdin(),
275274
},
276275
},
277276
"stdinenablednotvariadic": &cmds.Command{
278-
Arguments: []cmdkit.Argument{
279-
cmdkit.StringArg("a", true, false, "some arg").EnableStdin(),
277+
Arguments: []cmds.Argument{
278+
cmds.StringArg("a", true, false, "some arg").EnableStdin(),
280279
},
281280
},
282281
"stdinenablednotvariadic2args": &cmds.Command{
283-
Arguments: []cmdkit.Argument{
284-
cmdkit.StringArg("a", true, false, "some arg"),
285-
cmdkit.StringArg("b", true, false, "another arg").EnableStdin(),
282+
Arguments: []cmds.Argument{
283+
cmds.StringArg("a", true, false, "some arg"),
284+
cmds.StringArg("b", true, false, "another arg").EnableStdin(),
286285
},
287286
},
288287
"optionalsecond": {
289-
Arguments: []cmdkit.Argument{
290-
cmdkit.StringArg("a", true, false, "some arg"),
291-
cmdkit.StringArg("b", false, false, "another arg"),
288+
Arguments: []cmds.Argument{
289+
cmds.StringArg("a", true, false, "some arg"),
290+
cmds.StringArg("b", false, false, "another arg"),
292291
},
293292
},
294293
"optionalstdin": {
295-
Arguments: []cmdkit.Argument{
296-
cmdkit.StringArg("a", true, false, "some arg"),
297-
cmdkit.StringArg("b", false, false, "another arg").EnableStdin(),
294+
Arguments: []cmds.Argument{
295+
cmds.StringArg("a", true, false, "some arg"),
296+
cmds.StringArg("b", false, false, "another arg").EnableStdin(),
298297
},
299298
},
300299
"optionalvariadicstdin": {
301-
Arguments: []cmdkit.Argument{
302-
cmdkit.StringArg("a", true, false, "some arg"),
303-
cmdkit.StringArg("b", false, true, "another arg").EnableStdin(),
300+
Arguments: []cmds.Argument{
301+
cmds.StringArg("a", true, false, "some arg"),
302+
cmds.StringArg("b", false, true, "another arg").EnableStdin(),
304303
},
305304
},
306305
},

cli/run.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/ipfs/go-ipfs-cmdkit"
12-
cmds "github.com/ipfs/go-ipfs-cmds"
11+
"github.com/ipfs/go-ipfs-cmds"
1312
)
1413

1514
// ExitError is the error used when a specific exit code needs to be returned.
@@ -141,10 +140,10 @@ func Run(ctx context.Context, root *cmds.Command,
141140
if err != nil {
142141
printErr(err)
143142

144-
if kiterr, ok := err.(*cmdkit.Error); ok {
143+
if kiterr, ok := err.(*cmds.Error); ok {
145144
err = *kiterr
146145
}
147-
if kiterr, ok := err.(cmdkit.Error); ok && kiterr.Code == cmdkit.ErrClient {
146+
if kiterr, ok := err.(cmds.Error); ok && kiterr.Code == cmds.ErrClient {
148147
printMetaHelp(stderr)
149148
}
150149

0 commit comments

Comments
 (0)