2020-08-17 03:51:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-07-23 13:53:22 +00:00
|
|
|
|
2020-08-17 03:51:04 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-07-23 12:57:42 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-08-17 03:51:04 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/node/config"
|
2021-07-23 13:53:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2020-08-17 03:51:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var configCmd = &cli.Command{
|
2020-08-18 16:27:28 +00:00
|
|
|
Name: "config",
|
2021-07-23 12:57:42 +00:00
|
|
|
Usage: "Manage node config",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
configDefaultCmd,
|
|
|
|
configUpdateCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configDefaultCmd = &cli.Command{
|
|
|
|
Name: "default",
|
|
|
|
Usage: "Print default node config",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-comment",
|
|
|
|
Usage: "don't comment default values",
|
|
|
|
},
|
|
|
|
},
|
2020-08-17 03:51:04 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2021-07-23 12:57:42 +00:00
|
|
|
c := config.DefaultStorageMiner()
|
|
|
|
|
2023-03-20 16:19:14 +00:00
|
|
|
cb, err := config.ConfigUpdate(c, nil, config.Commented(!cctx.Bool("no-comment")))
|
2021-07-23 12:57:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(cb))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configUpdateCmd = &cli.Command{
|
|
|
|
Name: "updated",
|
|
|
|
Usage: "Print updated node config",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-comment",
|
|
|
|
Usage: "don't comment default values",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2021-07-23 13:53:22 +00:00
|
|
|
r, err := repo.NewFS(cctx.String(FlagMinerRepo))
|
2021-07-23 12:57:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ok, err := r.Exists()
|
2020-08-17 03:51:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-23 12:57:42 +00:00
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return xerrors.Errorf("repo not initialized")
|
|
|
|
}
|
|
|
|
|
|
|
|
lr, err := r.LockRO(repo.StorageMiner)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("locking repo: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgNode, err := lr.Config()
|
|
|
|
if err != nil {
|
|
|
|
_ = lr.Close()
|
|
|
|
return xerrors.Errorf("getting node config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := lr.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgDef := config.DefaultStorageMiner()
|
|
|
|
|
2023-03-20 16:19:14 +00:00
|
|
|
updated, err := config.ConfigUpdate(cfgNode, cfgDef, config.Commented(!cctx.Bool("no-comment")))
|
2021-07-23 12:57:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Print(string(updated))
|
2020-08-17 03:51:04 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|