From b03c4bc26b68c8e23a33694953699ea770f5ff71 Mon Sep 17 00:00:00 2001 From: zgfzgf <1901989065@qq.com> Date: Sat, 28 Nov 2020 17:29:15 +0800 Subject: [PATCH] add bitfield hex encode --- cmd/lotus-shed/bitfield.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/lotus-shed/bitfield.go b/cmd/lotus-shed/bitfield.go index 442cbef48..e377dba1e 100644 --- a/cmd/lotus-shed/bitfield.go +++ b/cmd/lotus-shed/bitfield.go @@ -17,6 +17,7 @@ import ( var bitFieldCmd = &cli.Command{ Name: "bitfield", + Usage: "Analyze tool", Description: "analyze bitfields", Flags: []cli.Flag{ &cli.StringFlag{ @@ -305,15 +306,9 @@ var bitFieldSubCmd = &cli.Command{ var bitFieldEncodeCmd = &cli.Command{ Name: "encode", + Usage: "Decimal number to bitfield", Description: "encode a series of decimal numbers into a bitfield", ArgsUsage: "[infile]", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "enc", - Value: "base64", - Usage: "specify input encoding to parse", - }, - }, Action: func(cctx *cli.Context) error { f, err := os.Open(cctx.Args().First()) if err != nil { @@ -340,8 +335,14 @@ var bitFieldEncodeCmd = &cli.Command{ if err != nil { return err } - - fmt.Println(base64.StdEncoding.EncodeToString(bytes)) + switch cctx.String("enc") { + case "base64": + fmt.Println(base64.StdEncoding.EncodeToString(bytes)) + case "hex": + fmt.Println(hex.EncodeToString(bytes)) + default: + return fmt.Errorf("unrecognized encoding: %s", cctx.String("enc")) + } return nil },