From 1888b68e38a060b747fcc920ec0bd46e98f26260 Mon Sep 17 00:00:00 2001 From: lanzafame Date: Wed, 11 Dec 2019 12:06:28 +1000 Subject: [PATCH] accept humanized size values to cli flags --- cli/params.go | 12 +++++++++--- cmd/lotus-bench/main.go | 12 +++++++++--- go.mod | 1 + go.sum | 2 ++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cli/params.go b/cli/params.go index df7e240ec..11a956120 100644 --- a/cli/params.go +++ b/cli/params.go @@ -1,6 +1,7 @@ package cli import ( + "github.com/docker/go-units" "github.com/filecoin-project/lotus/build" "golang.org/x/xerrors" "gopkg.in/urfave/cli.v2" @@ -10,13 +11,18 @@ var fetchParamCmd = &cli.Command{ Name: "fetch-params", Usage: "Fetch proving parameters", Flags: []cli.Flag{ - &cli.Uint64Flag{ + &cli.StringFlag{ 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 { - 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 { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus-bench/main.go b/cmd/lotus-bench/main.go index 7964186f2..b94cb8fa0 100644 --- a/cmd/lotus-bench/main.go +++ b/cmd/lotus-bench/main.go @@ -5,6 +5,7 @@ import ( "context" "crypto/sha256" "fmt" + "github.com/docker/go-units" "io/ioutil" "math/rand" "os" @@ -60,9 +61,10 @@ func main() { Value: "~/.lotus-bench", Usage: "Path to the storage directory that will store sectors long term", }, - &cli.Uint64Flag{ + &cli.StringFlag{ Name: "sector-size", - Value: 1024, + Value: "1GiB", + Usage: "size of the sectors in bytes, i.e. 32GiB", }, &cli.BoolFlag{ Name: "no-gpu", @@ -95,7 +97,11 @@ func main() { 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() cfg := §orbuilder.Config{ diff --git a/go.mod b/go.mod index 32b469d60..b6d315e20 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/GeertJohan/go.rice v1.0.0 github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee 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/filecoin-project/chain-validation v0.0.3 github.com/filecoin-project/filecoin-ffi v0.0.0-20191204125133-ebb3e13addf1 diff --git a/go.sum b/go.sum index c6c110dab..057e138a0 100644 --- a/go.sum +++ b/go.sum @@ -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-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= 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/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=