Skip to content

Commit 35a87e9

Browse files
committed
expand path names for add command, and pass errors up even more
1 parent b55a507 commit 35a87e9

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

cmd/ipfs/add.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ func addCmd(c *commander.Command, inp []string) error {
5151
return err
5252
}
5353

54-
err = commands.Add(n, cmd.Args, cmd.Opts, os.Stdout)
55-
if err != nil {
56-
fmt.Println(err)
57-
}
54+
return commands.Add(n, cmd.Args, cmd.Opts, os.Stdout)
5855
}
5956
return nil
6057
}

cmd/ipfs/cat.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"os"
65

76
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
@@ -29,6 +28,11 @@ func catCmd(c *commander.Command, inp []string) error {
2928
return nil
3029
}
3130

31+
expanded, err := u.ExpandPathnames(inp)
32+
if err != nil {
33+
return err
34+
}
35+
3236
com := daemon.NewCommand()
3337
com.Command = "cat"
3438
com.Args = inp
@@ -40,10 +44,7 @@ func catCmd(c *commander.Command, inp []string) error {
4044
return err
4145
}
4246

43-
err = commands.Cat(n, com.Args, com.Opts, os.Stdout)
44-
if err != nil {
45-
fmt.Println(err)
46-
}
47+
return commands.Cat(n, com.Args, com.Opts, os.Stdout)
4748
}
4849
return nil
4950
}

cmd/ipfs/ls.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ func lsCmd(c *commander.Command, inp []string) error {
4343
return err
4444
}
4545

46-
err = commands.Ls(n, com.Args, com.Opts, os.Stdout)
47-
if err != nil {
48-
fmt.Println(err)
49-
}
46+
return commands.Ls(n, com.Args, com.Opts, os.Stdout)
5047
}
5148

5249
return nil

util/util.go

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/user"
8+
"path/filepath"
89
"strings"
910

1011
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
@@ -78,3 +79,15 @@ func DOut(format string, a ...interface{}) {
7879
POut(format, a...)
7980
}
8081
}
82+
83+
func ExpandPathnames(paths []string) ([]string, error) {
84+
var out []string
85+
for _, p := range paths {
86+
abspath, err := filepath.Abs(p)
87+
if err != nil {
88+
return nil, err
89+
}
90+
out = append(out, abspath)
91+
}
92+
return out, nil
93+
}

0 commit comments

Comments
 (0)