accept humanized size values to cli flags

This commit is contained in:
lanzafame 2019-12-11 12:06:28 +10:00
parent a4b3f00628
commit 1888b68e38
4 changed files with 21 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package cli package cli
import ( import (
"github.com/docker/go-units"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -10,13 +11,18 @@ var fetchParamCmd = &cli.Command{
Name: "fetch-params", Name: "fetch-params",
Usage: "Fetch proving parameters", Usage: "Fetch proving parameters",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.Uint64Flag{ &cli.StringFlag{
Name: "proving-params", Name: "proving-params",
Usage: "download params used creating proofs for given size", Usage: "download params used creating proofs for given size, i.e. 32GiB",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
err := build.GetParams(cctx.Uint64("proving-params")) sectorSizeInt, err := units.FromHumanSize(cctx.String("proving-params"))
if err != nil {
return err
}
sectorSize := uint64(sectorSizeInt)
err = build.GetParams(sectorSize)
if err != nil { if err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err) return xerrors.Errorf("fetching proof parameters: %w", err)
} }

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"github.com/docker/go-units"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
@ -60,9 +61,10 @@ func main() {
Value: "~/.lotus-bench", Value: "~/.lotus-bench",
Usage: "Path to the storage directory that will store sectors long term", Usage: "Path to the storage directory that will store sectors long term",
}, },
&cli.Uint64Flag{ &cli.StringFlag{
Name: "sector-size", Name: "sector-size",
Value: 1024, Value: "1GiB",
Usage: "size of the sectors in bytes, i.e. 32GiB",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "no-gpu", Name: "no-gpu",
@ -95,7 +97,11 @@ func main() {
return err return err
} }
sectorSize := c.Uint64("sector-size") sectorSizeInt, err := units.FromHumanSize(c.String("sector-size"))
if err != nil {
return err
}
sectorSize := uint64(sectorSizeInt)
mds := datastore.NewMapDatastore() mds := datastore.NewMapDatastore()
cfg := &sectorbuilder.Config{ cfg := &sectorbuilder.Config{

1
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/GeertJohan/go.rice v1.0.0 github.com/GeertJohan/go.rice v1.0.0
github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/docker/go-units v0.4.0
github.com/fatih/color v1.7.0 // indirect github.com/fatih/color v1.7.0 // indirect
github.com/filecoin-project/chain-validation v0.0.3 github.com/filecoin-project/chain-validation v0.0.3
github.com/filecoin-project/filecoin-ffi v0.0.0-20191204125133-ebb3e13addf1 github.com/filecoin-project/filecoin-ffi v0.0.0-20191204125133-ebb3e13addf1

2
go.sum
View File

@ -68,6 +68,8 @@ github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhY
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=