Skip to content

Commit 41625b2

Browse files
authored
more verbose output to tell what is happening (#192)
Closes #43
1 parent cdf4765 commit 41625b2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

http.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package main
22

33
import (
44
"context"
5+
"fmt"
6+
"os"
57

68
ipfshttp "github.com/ipfs/kubo/client/rpc"
79
iface "github.com/ipfs/kubo/core/coreiface"
810
)
911

1012
func http(ctx context.Context) (iface.CoreAPI, error) {
13+
fmt.Fprint(os.Stderr, "Downloading from local daemon... ")
14+
1115
httpAPI, err := ipfshttp.NewLocalApi()
1216
if err != nil {
1317
return nil, err

main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func main() {
8585
if errors.Is(err, context.Canceled) {
8686
os.Exit(2)
8787
}
88+
if errors.Is(err, context.DeadlineExceeded) {
89+
err = errors.New("timed out")
90+
}
8891
fmt.Fprintln(os.Stderr, err)
8992
os.Exit(1)
9093
}
@@ -113,6 +116,7 @@ func ipgetAction(ctx context.Context, cmd *cli.Command) error {
113116
case "fallback":
114117
ipfs, err = http(ctx)
115118
if err != nil {
119+
fmt.Fprintln(os.Stderr, "failed")
116120
ipfs, err = spawn(ctx)
117121
}
118122
case "spawn":
@@ -125,15 +129,19 @@ func ipgetAction(ctx context.Context, cmd *cli.Command) error {
125129
return fmt.Errorf("no such 'node' strategy, %q", cmd.String("node"))
126130
}
127131
if err != nil {
132+
fmt.Fprintln(os.Stderr, "failed")
128133
return err
129134
}
130135

131136
go connect(ctx, ipfs, cmd.StringSlice("peers"))
132137

133138
out, err := ipfs.Unixfs().Get(ctx, iPath)
134139
if err != nil {
140+
fmt.Fprintln(os.Stderr, "failed")
135141
return err
136142
}
143+
fmt.Fprintln(os.Stderr, "succeeded")
144+
137145
if err = WriteTo(out, outPath, cmd.Bool("progress")); err != nil {
138146
return err
139147
}
@@ -204,7 +212,12 @@ func WriteTo(nd files.Node, fpath string, progress bool) error {
204212
bar = pb.New64(s).Start()
205213
}
206214

207-
return writeToRec(nd, fpath, bar)
215+
if err = writeToRec(nd, fpath, bar); err != nil {
216+
return err
217+
}
218+
219+
fmt.Fprintf(os.Stderr, "Saved to %s [%d bytes]\n", fpath, s)
220+
return nil
208221
}
209222

210223
func writeToRec(nd files.Node, fpath string, bar *pb.ProgressBar) error {

node.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
type CfgOpt func(*config.Config)
2121

2222
func spawn(ctx context.Context) (iface.CoreAPI, error) {
23+
fmt.Fprint(os.Stderr, "Downloading from IPFS node with existing repo... ")
24+
2325
defaultPath, err := config.PathRoot()
2426
if err != nil {
2527
// shouldn't be possible
@@ -32,6 +34,7 @@ func spawn(ctx context.Context) (iface.CoreAPI, error) {
3234

3335
ipfs, err := open(ctx, defaultPath)
3436
if err != nil {
37+
fmt.Fprintln(os.Stderr, "failed")
3538
return tmpNode(ctx)
3639
}
3740

@@ -91,6 +94,8 @@ func temp(ctx context.Context) (iface.CoreAPI, error) {
9194
}
9295

9396
func tmpNode(ctx context.Context) (iface.CoreAPI, error) {
97+
fmt.Fprint(os.Stderr, "Downloading from IPFS node with temporary repo... ")
98+
9499
dir, err := os.MkdirTemp("", "ipfs-shell")
95100
if err != nil {
96101
return nil, fmt.Errorf("failed to get temp dir: %s", err)

0 commit comments

Comments
 (0)