-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
47 lines (38 loc) · 808 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"io"
"os"
cli "github.com/jawher/mow.cli"
fallback "github.com/noffle/fallback-ipfs-shell"
)
func main() {
cmd := cli.App("ipcat", "Retrieve IPFS object data and output it to stdout.")
cmd.Spec = "IPFS_PATH"
hash := cmd.String(cli.StringArg{
Name: "IPFS_PATH",
Value: "",
Desc: "the IPFS object path",
})
cmd.Action = func() {
if err := cat(*hash); err != nil {
fmt.Fprintf(os.Stderr, "ipcat failed: %s\n", err)
os.Exit(2)
}
}
cmd.Run(os.Args)
}
func cat(path string) error {
shell, err := fallback.NewShell()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
reader, err := shell.Cat(path)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
io.Copy(os.Stdout, reader)
return nil
}