Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 10885ce

Browse files
committedFeb 10, 2016
cleanup a bit, and add to 'get'
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 64d918a commit 10885ce

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed
 

‎core/commands/cat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ it contains.
3131
PreRun: func(req cmds.Request) error {
3232
verbose, _, _ := req.Option("verbose").Bool()
3333
if verbose {
34-
return PrintDebugLog(req)
34+
return PrintDebugLog(req, req.Arguments()[0])
3535
}
3636
return nil
3737
},

‎core/commands/debug.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
path "github.com/ipfs/go-ipfs/path"
1212
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
1313

14+
"golang.org/x/net/context"
1415
ma "gx/ipfs/QmR3JkmZBKYXgNMNsNZawm914455Qof3PEopwuVSeXG7aV/go-multiaddr"
1516
manet "gx/ipfs/QmYtzQmUwPFGxjCXctJ8e6GXS8sYfoXy2pdeMbS5SFWqRi/go-multiaddr-net"
1617
)
@@ -36,11 +37,17 @@ func GetEventStream(req cmds.Request) (<-chan map[string]interface{}, error) {
3637
return nil, err
3738
}
3839

40+
events := parseJsonStream(req.Context(), resp.Body)
41+
42+
return events, nil
43+
}
44+
45+
func parseJsonStream(ctx context.Context, r io.ReadCloser) chan map[string]interface{} {
3946
events := make(chan map[string]interface{})
4047
go func() {
41-
defer resp.Body.Close()
48+
defer r.Close()
4249

43-
dec := json.NewDecoder(resp.Body)
50+
dec := json.NewDecoder(r)
4451
for {
4552
var obj map[string]interface{}
4653
err := dec.Decode(&obj)
@@ -53,16 +60,16 @@ func GetEventStream(req cmds.Request) (<-chan map[string]interface{}, error) {
5360

5461
select {
5562
case events <- obj:
56-
case <-req.Context().Done():
63+
case <-ctx.Done():
5764
return
5865
}
5966
}
6067
}()
6168

62-
return events, nil
69+
return events
6370
}
6471

65-
func PrintDebugLog(req cmds.Request) error {
72+
func PrintDebugLog(req cmds.Request, targetstr string) error {
6673
events, err := GetEventStream(req)
6774
if err != nil {
6875
return err
@@ -72,7 +79,7 @@ func PrintDebugLog(req cmds.Request) error {
7279
fmt.Fprintf(os.Stderr, f+"\n", args...)
7380
}
7481

75-
p, err := path.ParsePath(req.Arguments()[0])
82+
p, err := path.ParsePath(targetstr)
7683
if err != nil {
7784
return err
7885
}

‎core/commands/get.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ may also specify the level of compression by specifying '-l=<1-9>'.
4444
cmds.BoolOption("archive", "a", "Output a TAR archive."),
4545
cmds.BoolOption("compress", "C", "Compress the output with GZIP compression."),
4646
cmds.IntOption("compression-level", "l", "The level of compression (1-9)."),
47+
cmds.BoolOption("verbose", "v", "enable verbose debug output"),
4748
},
4849
PreRun: func(req cmds.Request) error {
4950
_, err := getCompressOptions(req)
50-
return err
51+
if err != nil {
52+
return err
53+
}
54+
55+
verbose, _, _ := req.Option("verbose").Bool()
56+
if verbose {
57+
return PrintDebugLog(req, req.Arguments()[0])
58+
}
59+
60+
return nil
5161
},
5262
Run: func(req cmds.Request, res cmds.Response) {
5363
cmplvl, err := getCompressOptions(req)

0 commit comments

Comments
 (0)
Please sign in to comment.