Nicer lotus-miner config commands
This commit is contained in:
parent
8b1f19e94c
commit
4757b014bc
@ -2,21 +2,92 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/node/config"
|
"github.com/filecoin-project/lotus/node/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configCmd = &cli.Command{
|
var configCmd = &cli.Command{
|
||||||
Name: "config",
|
Name: "config",
|
||||||
Usage: "Output default configuration",
|
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",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
comm, err := config.ConfigComment(config.DefaultStorageMiner())
|
c := config.DefaultStorageMiner()
|
||||||
|
|
||||||
|
cb, err := config.ConfigUpdate(c, nil, !cctx.Bool("no-comment"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(string(comm))
|
|
||||||
|
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 {
|
||||||
|
r, err := repo.NewFS(cctx.String("repo"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := r.Exists()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
updated, err := config.ConfigUpdate(cfgNode, cfgDef, !cctx.Bool("no-comment"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(string(updated))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user