/
main.go
74 lines (62 loc) · 1.45 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"encoding/json"
"fmt"
"io"
"os"
"github.com/filecoin-project/boost/cmd"
llog "log"
"github.com/filecoin-project/boost/build"
"github.com/filecoin-project/boostd-data/shared/cliutil"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
)
var log = logging.Logger("boost")
func init() {
llog.SetOutput(io.Discard)
}
func main() {
app := &cli.App{
Name: "boost",
Usage: "Boost client for Filecoin",
EnableBashCompletion: true,
Version: build.UserVersion(),
Flags: []cli.Flag{
cmd.FlagRepo,
cliutil.FlagVeryVerbose,
cmd.FlagJson,
},
Commands: []*cli.Command{
initCmd,
dealCmd,
dealStatusCmd,
retrieveCmd,
offlineDealCmd,
providerCmd,
walletCmd,
},
}
app.Setup()
if err := app.Run(os.Args); err != nil {
if isJson, ok := app.Metadata["json"].(bool); isJson && ok {
resJson, err := json.Marshal(map[string]string{"error": err.Error()})
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("marshalling json: %w", err))
} else {
fmt.Fprintln(os.Stderr, string(resJson))
}
} else {
fmt.Fprintln(os.Stderr, "Error: "+err.Error())
}
os.Exit(1)
}
}
func before(cctx *cli.Context) error {
_ = logging.SetLogLevel("boost", "INFO")
if cliutil.IsVeryVerbose {
_ = logging.SetLogLevel("boost", "DEBUG")
_ = logging.SetLogLevel("boost-net", "DEBUG")
}
cctx.App.Metadata["json"] = cctx.Bool("json")
return nil
}