diff --git a/cli/backup.go b/cli/backup.go index 4d88d4bbc..83234a423 100644 --- a/cli/backup.go +++ b/cli/backup.go @@ -114,8 +114,8 @@ this command must be within this base path`, }, ArgsUsage: "[backup file path]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument") + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } if cctx.Bool("offline") { diff --git a/cli/chain.go b/cli/chain.go index 39f1608f5..814aebeed 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -946,8 +946,8 @@ var ChainBisectCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) - if cctx.Args().Len() < 4 { - return xerrors.New("need at least 4 args") + if cctx.NArg() < 4 { + return IncorrectNumArgs(cctx) } start, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1312,8 +1312,8 @@ var chainDecodeParamsCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) - if cctx.Args().Len() != 3 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + if cctx.NArg() != 3 { + return IncorrectNumArgs(cctx) } to, err := address.NewFromString(cctx.Args().First()) @@ -1391,8 +1391,8 @@ var chainEncodeParamsCmd = &cli.Command{ Action: func(cctx *cli.Context) error { afmt := NewAppFmt(cctx.App) - if cctx.Args().Len() != 3 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + if cctx.NArg() != 3 { + return IncorrectNumArgs(cctx) } method, err := strconv.ParseInt(cctx.Args().Get(1), 10, 64) diff --git a/cli/client.go b/cli/client.go index 5f2342b2b..377505363 100644 --- a/cli/client.go +++ b/cli/client.go @@ -130,7 +130,7 @@ var clientImportCmd = &cli.Command{ ctx := ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.New("expected input path as the only arg") + return IncorrectNumArgs(cctx) } absPath, err := filepath.Abs(cctx.Args().First()) @@ -212,8 +212,8 @@ var clientCommPCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) - if cctx.Args().Len() != 1 { - return fmt.Errorf("usage: commP ") + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } ret, err := api.ClientCalcCommP(ctx, cctx.Args().Get(0)) @@ -245,8 +245,8 @@ var clientCarGenCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) - if cctx.Args().Len() != 2 { - return fmt.Errorf("usage: generate-car ") + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ref := lapi.FileRef{ @@ -376,7 +376,7 @@ The minimum value is 518400 (6 months).`, afmt := NewAppFmt(cctx.App) if cctx.NArg() != 4 { - return xerrors.New(expectedArgsMsg) + return IncorrectNumArgs(cctx) } // [data, miner, price, dur] diff --git a/cli/client_retr.go b/cli/client_retr.go index f32e5d4e4..3fe656f15 100644 --- a/cli/client_retr.go +++ b/cli/client_retr.go @@ -289,7 +289,7 @@ Examples: }, retrFlagsCommon...), Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + return IncorrectNumArgs(cctx) } if cctx.Bool("car-export-merkle-proof") { @@ -405,7 +405,7 @@ var clientRetrieveCatCmd = &cli.Command{ }, retrFlagsCommon...), Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + return IncorrectNumArgs(cctx) } ainfo, err := GetAPIInfo(cctx, repo.FullNode) @@ -484,7 +484,7 @@ var clientRetrieveLsCmd = &cli.Command{ }, retrFlagsCommon...), Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + return IncorrectNumArgs(cctx) } ainfo, err := GetAPIInfo(cctx, repo.FullNode) diff --git a/cli/filplus.go b/cli/filplus.go index 66de32d0c..d74171dd6 100644 --- a/cli/filplus.go +++ b/cli/filplus.go @@ -61,8 +61,8 @@ var filplusVerifyClientCmd = &cli.Command{ return err } - if cctx.Args().Len() != 2 { - return fmt.Errorf("must specify two arguments: address and allowance") + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } target, err := address.NewFromString(cctx.Args().Get(0)) @@ -120,7 +120,7 @@ var filplusVerifyClientCmd = &cli.Command{ return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("failed to add verified client: %d", mwait.Receipt.ExitCode) } @@ -289,8 +289,8 @@ var filplusSignRemoveDataCapProposal = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return fmt.Errorf("must specify three arguments: notary address, client address, and allowance to remove") + if cctx.NArg() != 3 { + return IncorrectNumArgs(cctx) } api, closer, err := GetFullNodeAPI(cctx) diff --git a/cli/helper.go b/cli/helper.go index da236bcae..c4a61397c 100644 --- a/cli/helper.go +++ b/cli/helper.go @@ -31,6 +31,10 @@ func ShowHelp(cctx *ufcli.Context, err error) error { return &PrintHelpErr{Err: err, Ctx: cctx} } +func IncorrectNumArgs(cctx *ufcli.Context) error { + return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments, got %d", cctx.NArg())) +} + func RunApp(app *ufcli.App) { if err := app.Run(os.Args); err != nil { if os.Getenv("LOTUS_DEV") != "" { diff --git a/cli/mpool.go b/cli/mpool.go index 1410814b5..e098806cb 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -404,7 +404,7 @@ var MpoolReplaceCmd = &cli.Command{ var from address.Address var nonce uint64 - switch cctx.Args().Len() { + switch cctx.NArg() { case 1: mcid, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -610,8 +610,8 @@ var MpoolConfig = &cli.Command{ Usage: "get or set current mpool configuration", ArgsUsage: "[new-config]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() > 1 { - return cli.ShowCommandHelp(cctx, cctx.Command.Name) + if cctx.NArg() > 1 { + return IncorrectNumArgs(cctx) } afmt := NewAppFmt(cctx.App) @@ -624,7 +624,7 @@ var MpoolConfig = &cli.Command{ ctx := ReqContext(cctx) - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { cfg, err := api.MpoolGetConfig(ctx) if err != nil { return err diff --git a/cli/multisig.go b/cli/multisig.go index 67c833397..1dd7d01b8 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -88,8 +88,8 @@ var msigCreateCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 1 { - return ShowHelp(cctx, fmt.Errorf("multisigs must have at least one signer")) + if cctx.NArg() < 1 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -167,7 +167,7 @@ var msigCreateCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "actor creation failed!") return err } @@ -365,11 +365,11 @@ var msigProposeCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 3 { + if cctx.NArg() < 3 { return ShowHelp(cctx, fmt.Errorf("must pass at least multisig address, destination, and value")) } - if cctx.Args().Len() > 3 && cctx.Args().Len() != 5 { + if cctx.NArg() > 3 && cctx.NArg() != 5 { return ShowHelp(cctx, fmt.Errorf("must either pass three or five arguments")) } @@ -399,7 +399,7 @@ var msigProposeCmd = &cli.Command{ var method uint64 var params []byte - if cctx.Args().Len() == 5 { + if cctx.NArg() == 5 { m, err := strconv.ParseUint(cctx.Args().Get(3), 10, 64) if err != nil { return err @@ -456,7 +456,7 @@ var msigProposeCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("proposal returned exit %d", wait.Receipt.ExitCode) } @@ -487,15 +487,15 @@ var msigApproveCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 2 { + if cctx.NArg() < 2 { return ShowHelp(cctx, fmt.Errorf("must pass at least multisig address and message ID")) } - if cctx.Args().Len() > 2 && cctx.Args().Len() < 5 { + if cctx.NArg() > 2 && cctx.NArg() < 5 { return ShowHelp(cctx, fmt.Errorf("usage: msig approve ")) } - if cctx.Args().Len() > 5 && cctx.Args().Len() != 7 { + if cctx.NArg() > 5 && cctx.NArg() != 7 { return ShowHelp(cctx, fmt.Errorf("usage: msig approve [ ]")) } @@ -534,7 +534,7 @@ var msigApproveCmd = &cli.Command{ } var msgCid cid.Cid - if cctx.Args().Len() == 2 { + if cctx.NArg() == 2 { proto, err := api.MsigApprove(ctx, msig, txid, from) if err != nil { return err @@ -571,7 +571,7 @@ var msigApproveCmd = &cli.Command{ var method uint64 var params []byte - if cctx.Args().Len() == 7 { + if cctx.NArg() == 7 { m, err := strconv.ParseUint(cctx.Args().Get(5), 10, 64) if err != nil { return err @@ -605,7 +605,7 @@ var msigApproveCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("approve returned exit %d", wait.Receipt.ExitCode) } @@ -624,15 +624,15 @@ var msigCancelCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 2 { + if cctx.NArg() < 2 { return ShowHelp(cctx, fmt.Errorf("must pass at least multisig address and message ID")) } - if cctx.Args().Len() > 2 && cctx.Args().Len() < 4 { + if cctx.NArg() > 2 && cctx.NArg() < 4 { return ShowHelp(cctx, fmt.Errorf("usage: msig cancel ")) } - if cctx.Args().Len() > 4 && cctx.Args().Len() != 6 { + if cctx.NArg() > 4 && cctx.NArg() != 6 { return ShowHelp(cctx, fmt.Errorf("usage: msig cancel [ ]")) } @@ -671,7 +671,7 @@ var msigCancelCmd = &cli.Command{ } var msgCid cid.Cid - if cctx.Args().Len() == 2 { + if cctx.NArg() == 2 { proto, err := api.MsigCancel(ctx, msig, txid, from) if err != nil { return err @@ -696,7 +696,7 @@ var msigCancelCmd = &cli.Command{ var method uint64 var params []byte - if cctx.Args().Len() == 6 { + if cctx.NArg() == 6 { m, err := strconv.ParseUint(cctx.Args().Get(4), 10, 64) if err != nil { return err @@ -730,7 +730,7 @@ var msigCancelCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("cancel returned exit %d", wait.Receipt.ExitCode) } @@ -753,8 +753,8 @@ var msigRemoveProposeCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address and signer address")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -810,7 +810,7 @@ var msigRemoveProposeCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("add proposal returned exit %d", wait.Receipt.ExitCode) } @@ -840,8 +840,8 @@ var msigAddProposeCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address and signer address")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -930,7 +930,7 @@ var msigAddProposeCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("add proposal returned exit %d", wait.Receipt.ExitCode) } @@ -949,8 +949,8 @@ var msigAddApproveCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 5 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, transaction id, new signer address, whether to increase threshold")) + if cctx.NArg() != 5 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1021,7 +1021,7 @@ var msigAddApproveCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("add approval returned exit %d", wait.Receipt.ExitCode) } @@ -1040,8 +1040,8 @@ var msigAddCancelCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 4 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, transaction id, new signer address, whether to increase threshold")) + if cctx.NArg() != 4 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1107,7 +1107,7 @@ var msigAddCancelCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("add cancellation returned exit %d", wait.Receipt.ExitCode) } @@ -1126,8 +1126,8 @@ var msigSwapProposeCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, old signer address, new signer address")) + if cctx.NArg() != 3 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1188,7 +1188,7 @@ var msigSwapProposeCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("swap proposal returned exit %d", wait.Receipt.ExitCode) } @@ -1207,8 +1207,8 @@ var msigSwapApproveCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 5 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, transaction id, old signer address, new signer address")) + if cctx.NArg() != 5 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1279,7 +1279,7 @@ var msigSwapApproveCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("swap approval returned exit %d", wait.Receipt.ExitCode) } @@ -1298,8 +1298,8 @@ var msigSwapCancelCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 4 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, transaction id, old signer address, new signer address")) + if cctx.NArg() != 4 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1365,7 +1365,7 @@ var msigSwapCancelCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("swap cancellation returned exit %d", wait.Receipt.ExitCode) } @@ -1384,8 +1384,8 @@ var msigLockProposeCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 4 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, start epoch, unlock duration, and amount")) + if cctx.NArg() != 4 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1461,7 +1461,7 @@ var msigLockProposeCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("lock proposal returned exit %d", wait.Receipt.ExitCode) } @@ -1480,8 +1480,8 @@ var msigLockApproveCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 6 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, tx id, start epoch, unlock duration, and amount")) + if cctx.NArg() != 6 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1567,7 +1567,7 @@ var msigLockApproveCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("lock approval returned exit %d", wait.Receipt.ExitCode) } @@ -1586,8 +1586,8 @@ var msigLockCancelCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 5 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, tx id, start epoch, unlock duration, and amount")) + if cctx.NArg() != 5 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1668,7 +1668,7 @@ var msigLockCancelCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("lock cancellation returned exit %d", wait.Receipt.ExitCode) } @@ -1693,8 +1693,8 @@ var msigVestedCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address")) + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } api, closer, err := GetFullNodeAPI(cctx) @@ -1749,8 +1749,8 @@ var msigProposeThresholdCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address and new threshold value")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1814,7 +1814,7 @@ var msigProposeThresholdCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("change threshold proposal returned exit %d", wait.Receipt.ExitCode) } diff --git a/cli/net.go b/cli/net.go index 5a141e52d..b0615e0b1 100644 --- a/cli/net.go +++ b/cli/net.go @@ -141,8 +141,8 @@ var NetPing = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("please provide a peerID") + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } api, closer, err := GetAPI(cctx) diff --git a/cli/paych.go b/cli/paych.go index 8277e3123..1067d0913 100644 --- a/cli/paych.go +++ b/cli/paych.go @@ -50,8 +50,8 @@ var paychAddFundsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return ShowHelp(cctx, fmt.Errorf("must pass three arguments: ")) + if cctx.NArg() != 3 { + return IncorrectNumArgs(cctx) } from, err := address.NewFromString(cctx.Args().Get(0)) @@ -112,8 +112,8 @@ var paychStatusByFromToCmd = &cli.Command{ Usage: "Show the status of an active outbound payment channel by from/to addresses", ArgsUsage: "[fromAddress toAddress]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass two arguments: ")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ctx := ReqContext(cctx) @@ -148,8 +148,8 @@ var paychStatusCmd = &cli.Command{ Usage: "Show the status of an outbound payment channel", ArgsUsage: "[channelAddress]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass an argument: ")) + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } ctx := ReqContext(cctx) @@ -260,8 +260,8 @@ var paychSettleCmd = &cli.Command{ Usage: "Settle a payment channel", ArgsUsage: "[channelAddress]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return fmt.Errorf("must pass payment channel address") + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -286,7 +286,7 @@ var paychSettleCmd = &cli.Command{ if err != nil { return nil } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("settle message execution failed (exit code %d)", mwait.Receipt.ExitCode) } @@ -300,8 +300,8 @@ var paychCloseCmd = &cli.Command{ Usage: "Collect funds for a payment channel", ArgsUsage: "[channelAddress]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return fmt.Errorf("must pass payment channel address") + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -326,7 +326,7 @@ var paychCloseCmd = &cli.Command{ if err != nil { return nil } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("collect message execution failed (exit code %d)", mwait.Receipt.ExitCode) } @@ -360,8 +360,8 @@ var paychVoucherCreateCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass two arguments: ")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -408,8 +408,8 @@ var paychVoucherCheckCmd = &cli.Command{ Usage: "Check validity of payment channel voucher", ArgsUsage: "[channelAddress voucher]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher to validate")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -444,8 +444,8 @@ var paychVoucherAddCmd = &cli.Command{ Usage: "Add payment channel voucher to local datastore", ArgsUsage: "[channelAddress voucher]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -486,8 +486,8 @@ var paychVoucherListCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address")) + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -531,8 +531,8 @@ var paychVoucherBestSpendableCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address")) + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -602,8 +602,8 @@ var paychVoucherSubmitCmd = &cli.Command{ Usage: "Submit voucher to chain to update payment channel state", ArgsUsage: "[channelAddress voucher]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -634,7 +634,7 @@ var paychVoucherSubmitCmd = &cli.Command{ return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("message execution failed (exit code %d)", mwait.Receipt.ExitCode) } diff --git a/cli/send.go b/cli/send.go index b5bfd3eb0..4268f8eb2 100644 --- a/cli/send.go +++ b/cli/send.go @@ -67,8 +67,8 @@ var sendCmd = &cli.Command{ fmt.Println("'force' flag is deprecated, use global flag 'force-send'") } - if cctx.Args().Len() != 2 { - return ShowHelp(cctx, fmt.Errorf("'send' expects two arguments, target and amount")) + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) diff --git a/cli/state.go b/cli/state.go index bea7ed0df..a7e195b1c 100644 --- a/cli/state.go +++ b/cli/state.go @@ -504,9 +504,8 @@ var StateReplayCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - fmt.Println("must provide cid of message to replay") - return nil + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) } mcid, err := cid.Decode(cctx.Args().First()) @@ -1580,8 +1579,8 @@ var StateCallCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 2 { - return fmt.Errorf("must specify at least actor and method to invoke") + if cctx.NArg() < 2 { + return ShowHelp(cctx, fmt.Errorf("must specify at least actor and method to invoke")) } api, closer, err := GetFullNodeAPI(cctx) @@ -1619,7 +1618,7 @@ var StateCallCmd = &cli.Command{ var params []byte // If params were passed in, decode them - if cctx.Args().Len() > 2 { + if cctx.NArg() > 2 { switch cctx.String("encoding") { case "base64": params, err = base64.StdEncoding.DecodeString(cctx.Args().Get(2)) @@ -1743,8 +1742,8 @@ var StateSectorCmd = &cli.Command{ ctx := ReqContext(cctx) - if cctx.Args().Len() != 2 { - return xerrors.Errorf("expected 2 params: minerAddress and sectorNumber") + if cctx.NArg() != 2 { + return IncorrectNumArgs(cctx) } ts, err := LoadTipSet(ctx, cctx, api) diff --git a/cli/wallet.go b/cli/wallet.go index 4193138c3..56c1532f4 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -645,7 +645,7 @@ var walletMarketWithdraw = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { afmt.Println(cctx.App.Writer, "withdrawal failed!") return err } diff --git a/cmd/lotus-bench/simple.go b/cmd/lotus-bench/simple.go index b999cd277..87e2c3bc0 100644 --- a/cmd/lotus-bench/simple.go +++ b/cmd/lotus-bench/simple.go @@ -959,7 +959,7 @@ var simpleProveReplicaUpdate2 = &cli.Command{ } func ParsePieceInfos(cctx *cli.Context, firstArg int) ([]abi.PieceInfo, error) { - args := cctx.Args().Len() - firstArg + args := cctx.NArg() - firstArg if args%2 != 0 { return nil, xerrors.Errorf("piece info argunemts need to be supplied in pairs") } diff --git a/cmd/lotus-miner/actor.go b/cmd/lotus-miner/actor.go index c1b86b59c..aad110414 100644 --- a/cmd/lotus-miner/actor.go +++ b/cmd/lotus-miner/actor.go @@ -81,7 +81,7 @@ var actorSetAddrsCmd = &cli.Command{ return fmt.Errorf("unset can only be used with no arguments") } - nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -112,7 +112,7 @@ var actorSetAddrsCmd = &cli.Command{ addrs = append(addrs, maddrNop2p.Bytes()) } - maddr, err := nodeAPI.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -177,7 +177,7 @@ var actorSetPeeridCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -196,7 +196,7 @@ var actorSetPeeridCmd = &cli.Command{ return fmt.Errorf("failed to parse input as a peerId: %w", err) } - maddr, err := nodeAPI.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -258,7 +258,7 @@ var actorWithdrawCmd = &cli.Command{ amount = abi.TokenAmount(f) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -274,9 +274,9 @@ var actorWithdrawCmd = &cli.Command{ var res cid.Cid if cctx.IsSet("beneficiary") { - res, err = nodeApi.BeneficiaryWithdrawBalance(ctx, amount) + res, err = minerApi.BeneficiaryWithdrawBalance(ctx, amount) } else { - res, err = nodeApi.ActorWithdrawBalance(ctx, amount) + res, err = minerApi.ActorWithdrawBalance(ctx, amount) } if err != nil { return err @@ -290,7 +290,7 @@ var actorWithdrawCmd = &cli.Command{ return xerrors.Errorf("Timeout waiting for withdrawal message %s", wait.Message) } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return xerrors.Errorf("Failed to execute withdrawal message %s: %w", wait.Message, wait.Receipt.ExitCode.Error()) } @@ -326,7 +326,7 @@ var actorRepayDebtCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -340,7 +340,7 @@ var actorRepayDebtCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -441,7 +441,7 @@ var actorControlList = &cli.Command{ color.NoColor = !cctx.Bool("color") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -473,7 +473,7 @@ var actorControlList = &cli.Command{ tablewriter.Col("balance"), ) - ac, err := nodeApi.ActorAddressConfig(ctx) + ac, err := minerApi.ActorAddressConfig(ctx) if err != nil { return err } @@ -610,7 +610,7 @@ var actorControlSet = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -624,7 +624,7 @@ var actorControlSet = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -729,7 +729,7 @@ var actorSetOwnerCmd = &cli.Command{ } if cctx.NArg() != 2 { - return fmt.Errorf("must pass new owner address and sender address") + return lcli.IncorrectNumArgs(cctx) } api, acloser, err := lcli.GetFullNodeAPI(cctx) @@ -799,7 +799,7 @@ var actorSetOwnerCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println("owner change failed!") return err } @@ -826,7 +826,7 @@ var actorProposeChangeWorker = &cli.Command{ return fmt.Errorf("must pass address of new worker address") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -850,7 +850,7 @@ var actorProposeChangeWorker = &cli.Command{ return err } - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -905,7 +905,7 @@ var actorProposeChangeWorker = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose worker change failed!") return err } @@ -941,7 +941,7 @@ var actorConfirmChangeWorker = &cli.Command{ return fmt.Errorf("must pass address of new worker address") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -965,7 +965,7 @@ var actorConfirmChangeWorker = &cli.Command{ return err } - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -1011,7 +1011,7 @@ var actorConfirmChangeWorker = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Worker change failed!") return err } @@ -1056,7 +1056,7 @@ var actorCompactAllocatedCmd = &cli.Command{ return fmt.Errorf("must pass address of new owner address") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -1070,7 +1070,7 @@ var actorCompactAllocatedCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -1170,7 +1170,7 @@ var actorCompactAllocatedCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println("Propose owner change failed!") return err } diff --git a/cmd/lotus-miner/dagstore.go b/cmd/lotus-miner/dagstore.go index 37d048825..519b43cc7 100644 --- a/cmd/lotus-miner/dagstore.go +++ b/cmd/lotus-miner/dagstore.go @@ -77,7 +77,7 @@ var dagstoreRegisterShardCmd = &cli.Command{ } if cctx.NArg() != 1 { - return fmt.Errorf("must provide a single shard key") + return lcli.IncorrectNumArgs(cctx) } marketsAPI, closer, err := lcli.GetMarketsAPI(cctx) @@ -116,7 +116,7 @@ var dagstoreInitializeShardCmd = &cli.Command{ } if cctx.NArg() != 1 { - return fmt.Errorf("must provide a single shard key") + return lcli.IncorrectNumArgs(cctx) } marketsApi, closer, err := lcli.GetMarketsAPI(cctx) @@ -148,7 +148,7 @@ var dagstoreRecoverShardCmd = &cli.Command{ } if cctx.NArg() != 1 { - return fmt.Errorf("must provide a single shard key") + return lcli.IncorrectNumArgs(cctx) } marketsApi, closer, err := lcli.GetMarketsAPI(cctx) @@ -330,7 +330,7 @@ var dagstoreLookupPiecesCmd = &cli.Command{ } if cctx.NArg() != 1 { - return fmt.Errorf("must provide a CID") + return lcli.IncorrectNumArgs(cctx) } cidStr := cctx.Args().First() diff --git a/cmd/lotus-miner/index_provider.go b/cmd/lotus-miner/index_provider.go index 1e4b69d86..4ed14549d 100644 --- a/cmd/lotus-miner/index_provider.go +++ b/cmd/lotus-miner/index_provider.go @@ -36,7 +36,7 @@ var indexProvAnnounceCmd = &cli.Command{ } if cctx.NArg() != 1 { - return fmt.Errorf("must provide the deal proposal CID") + return lcli.IncorrectNumArgs(cctx) } proposalCidStr := cctx.Args().First() diff --git a/cmd/lotus-miner/info_all.go b/cmd/lotus-miner/info_all.go index 38cc7fc05..bf6d7e4b9 100644 --- a/cmd/lotus-miner/info_all.go +++ b/cmd/lotus-miner/info_all.go @@ -16,7 +16,7 @@ var infoAllCmd = &cli.Command{ Name: "all", Usage: "dump all related miner info", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -220,7 +220,7 @@ var infoAllCmd = &cli.Command{ // Very Very Verbose info fmt.Println("\n#: Per Sector Info") - list, err := nodeApi.SectorsList(ctx) + list, err := minerApi.SectorsList(ctx) if err != nil { fmt.Println("ERROR: ", err) } diff --git a/cmd/lotus-miner/init_restore.go b/cmd/lotus-miner/init_restore.go index a54146fb2..3d179f3ba 100644 --- a/cmd/lotus-miner/init_restore.go +++ b/cmd/lotus-miner/init_restore.go @@ -96,8 +96,8 @@ var restoreCmd = &cli.Command{ } func restore(ctx context.Context, cctx *cli.Context, targetPath string, strConfig *paths.StorageConfig, manageConfig func(*config.StorageMiner) error, after func(api lapi.FullNode, addr address.Address, peerid peer.ID, mi api.MinerInfo) error) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } log.Info("Trying to connect to full node RPC") diff --git a/cmd/lotus-miner/main.go b/cmd/lotus-miner/main.go index 0462373ae..3cc796168 100644 --- a/cmd/lotus-miner/main.go +++ b/cmd/lotus-miner/main.go @@ -177,13 +177,13 @@ func getActorAddress(ctx context.Context, cctx *cli.Context) (maddr address.Addr return } - nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return address.Undef, err } defer closer() - maddr, err = nodeAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return maddr, xerrors.Errorf("getting actor address: %w", err) } diff --git a/cmd/lotus-miner/market.go b/cmd/lotus-miner/market.go index 37d252efa..706e49236 100644 --- a/cmd/lotus-miner/market.go +++ b/cmd/lotus-miner/market.go @@ -370,8 +370,8 @@ var dealsImportDataCmd = &cli.Command{ ctx := lcli.DaemonContext(cctx) - if cctx.Args().Len() < 2 { - return fmt.Errorf("must specify proposal CID and file path") + if cctx.NArg() != 2 { + return lcli.IncorrectNumArgs(cctx) } propCid, err := cid.Decode(cctx.Args().Get(0)) @@ -617,8 +617,8 @@ var setSealDurationCmd = &cli.Command{ } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass duration in minutes") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } hs, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index 85bc48e78..6f6fd6635 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -314,8 +314,8 @@ var provingDeadlineInfoCmd = &cli.Command{ ArgsUsage: "", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass deadline index") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } dlIdx, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -461,8 +461,8 @@ var provingCheckProvableCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass deadline index") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } dlIdx, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -476,7 +476,7 @@ var provingCheckProvableCmd = &cli.Command{ } defer closer() - sapi, scloser, err := lcli.GetStorageMinerAPI(cctx) + minerApi, scloser, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -484,7 +484,7 @@ var provingCheckProvableCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - addr, err := sapi.ActorAddress(ctx) + addr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -510,7 +510,7 @@ var provingCheckProvableCmd = &cli.Command{ var filter map[abi.SectorID]struct{} if cctx.IsSet("storage-id") { - sl, err := sapi.StorageList(ctx) + sl, err := minerApi.StorageList(ctx) if err != nil { return err } @@ -582,7 +582,7 @@ var provingCheckProvableCmd = &cli.Command{ }) } - bad, err := sapi.CheckProvable(ctx, info.WindowPoStProofType, tocheck, cctx.Bool("slow")) + bad, err := minerApi.CheckProvable(ctx, info.WindowPoStProofType, tocheck, cctx.Bool("slow")) if err != nil { return err } @@ -616,8 +616,8 @@ var provingComputeWindowPoStCmd = &cli.Command{ It will not send any messages to the chain.`, ArgsUsage: "[deadline index]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass deadline index") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } dlIdx, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -625,7 +625,7 @@ It will not send any messages to the chain.`, return xerrors.Errorf("could not parse deadline index: %w", err) } - sapi, scloser, err := lcli.GetStorageMinerAPI(cctx) + minerApi, scloser, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -634,7 +634,7 @@ It will not send any messages to the chain.`, ctx := lcli.ReqContext(cctx) start := time.Now() - res, err := sapi.ComputeWindowPoSt(ctx, dlIdx, types.EmptyTSK) + res, err := minerApi.ComputeWindowPoSt(ctx, dlIdx, types.EmptyTSK) fmt.Printf("Took %s\n", time.Now().Sub(start)) if err != nil { return err @@ -661,8 +661,8 @@ var provingRecoverFaultsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 1 { - return xerrors.Errorf("must pass at least 1 sector number") + if cctx.NArg() < 1 { + return lcli.ShowHelp(cctx, xerrors.Errorf("must pass at least 1 sector number")) } arglist := cctx.Args().Slice() @@ -675,7 +675,7 @@ var provingRecoverFaultsCmd = &cli.Command{ sectors = append(sectors, abi.SectorNumber(s)) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -689,7 +689,7 @@ var provingRecoverFaultsCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - msgs, err := nodeApi.RecoverFault(ctx, sectors) + msgs, err := minerApi.RecoverFault(ctx, sectors) if err != nil { return err } @@ -707,7 +707,7 @@ var provingRecoverFaultsCmd = &cli.Command{ return } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { results <- xerrors.Errorf("Failed to execute message %s: %w", wait.Message, wait.Receipt.ExitCode.Error()) return } diff --git a/cmd/lotus-miner/sealing.go b/cmd/lotus-miner/sealing.go index 970f54a55..34c84772d 100644 --- a/cmd/lotus-miner/sealing.go +++ b/cmd/lotus-miner/sealing.go @@ -57,7 +57,7 @@ func workersCmd(sealing bool) *cli.Command { color.NoColor = !cctx.Bool("color") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -65,7 +65,7 @@ func workersCmd(sealing bool) *cli.Command { ctx := lcli.ReqContext(cctx) - stats, err := nodeApi.WorkerStats(ctx) + stats, err := minerApi.WorkerStats(ctx) if err != nil { return err } @@ -233,7 +233,7 @@ var sealingJobsCmd = &cli.Command{ color.NoColor = !cctx.Bool("color") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -241,7 +241,7 @@ var sealingJobsCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - jobs, err := nodeApi.WorkerJobs(ctx) + jobs, err := minerApi.WorkerJobs(ctx) if err != nil { return xerrors.Errorf("getting worker jobs: %w", err) } @@ -275,7 +275,7 @@ var sealingJobsCmd = &cli.Command{ workerHostnames := map[uuid.UUID]string{} - wst, err := nodeApi.WorkerStats(ctx) + wst, err := minerApi.WorkerStats(ctx) if err != nil { return xerrors.Errorf("getting worker stats: %w", err) } @@ -337,7 +337,7 @@ var sealingSchedDiagCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -345,7 +345,7 @@ var sealingSchedDiagCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - st, err := nodeApi.SealingSchedDiag(ctx, cctx.Bool("force-sched")) + st, err := minerApi.SealingSchedDiag(ctx, cctx.Bool("force-sched")) if err != nil { return err } @@ -372,11 +372,11 @@ var sealingAbortCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -385,14 +385,14 @@ var sealingAbortCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.Bool("sched") { - err = nodeApi.SealingRemoveRequest(ctx, uuid.Must(uuid.Parse(cctx.Args().First()))) + err = minerApi.SealingRemoveRequest(ctx, uuid.Must(uuid.Parse(cctx.Args().First()))) if err != nil { return xerrors.Errorf("Failed to removed the request with UUID %s: %w", cctx.Args().First(), err) } return nil } - jobs, err := nodeApi.WorkerJobs(ctx) + jobs, err := minerApi.WorkerJobs(ctx) if err != nil { return xerrors.Errorf("getting worker jobs: %w", err) } @@ -415,7 +415,7 @@ var sealingAbortCmd = &cli.Command{ fmt.Printf("aborting job %s, task %s, sector %d, running on host %s\n", job.ID.String(), job.Task.Short(), job.Sector.Number, job.Hostname) - return nodeApi.SealingAbort(ctx, job.ID) + return minerApi.SealingAbort(ctx, job.ID) }, } @@ -430,11 +430,11 @@ var sealingDataCidCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 1 || cctx.Args().Len() > 2 { - return xerrors.Errorf("expected 1 or 2 arguments") + if cctx.NArg() < 1 || cctx.NArg() > 2 { + return lcli.ShowHelp(cctx, xerrors.Errorf("expected 1 or 2 arguments")) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -484,7 +484,7 @@ var sealingDataCidCmd = &cli.Command{ } var psize abi.PaddedPieceSize - if cctx.Args().Len() == 2 { + if cctx.NArg() == 2 { rps, err := humanize.ParseBytes(cctx.Args().Get(1)) if err != nil { return xerrors.Errorf("parsing piece size: %w", err) @@ -500,7 +500,7 @@ var sealingDataCidCmd = &cli.Command{ psize = padreader.PaddedSize(sz).Padded() } - pc, err := nodeApi.ComputeDataCid(ctx, psize.Unpadded(), r) + pc, err := minerApi.ComputeDataCid(ctx, psize.Unpadded(), r) if err != nil { return xerrors.Errorf("computing data CID: %w", err) } diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index 45a1256aa..bcd60acf2 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -69,14 +69,14 @@ var sectorsPledgeCmd = &cli.Command{ Name: "pledge", Usage: "store random data in a sector", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - id, err := nodeApi.PledgeSector(ctx) + id, err := minerApi.PledgeSector(ctx) if err != nil { return err } @@ -113,7 +113,7 @@ var sectorsStatusCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -130,7 +130,7 @@ var sectorsStatusCmd = &cli.Command{ } onChainInfo := cctx.Bool("on-chain-info") - status, err := nodeApi.SectorsStatus(ctx, abi.SectorNumber(id), onChainInfo) + status, err := minerApi.SectorsStatus(ctx, abi.SectorNumber(id), onChainInfo) if err != nil { return err } @@ -318,7 +318,7 @@ var sectorsListCmd = &cli.Command{ color.NoColor = !cctx.Bool("color") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -359,16 +359,16 @@ var sectorsListCmd = &cli.Command{ } if len(states) == 0 { - list, err = nodeApi.SectorsList(ctx) + list, err = minerApi.SectorsList(ctx) } else { - list, err = nodeApi.SectorsListInStates(ctx, states) + list, err = minerApi.SectorsListInStates(ctx, states) } if err != nil { return err } - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -418,7 +418,7 @@ var sectorsListCmd = &cli.Command{ fast := cctx.Bool("fast") for _, s := range list { - st, err := nodeApi.SectorsStatus(ctx, s, !fast) + st, err := minerApi.SectorsStatus(ctx, s, !fast) if err != nil { tw.Write(map[string]interface{}{ "ID": s, @@ -1372,14 +1372,14 @@ var sectorsTerminateCmd = &cli.Command{ if !cctx.Bool("really-do-it") { return xerrors.Errorf("pass --really-do-it to confirm this action") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass sector number") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1387,7 +1387,7 @@ var sectorsTerminateCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - return nodeApi.SectorTerminate(ctx, abi.SectorNumber(id)) + return minerApi.SectorTerminate(ctx, abi.SectorNumber(id)) }, } @@ -1395,14 +1395,14 @@ var sectorsTerminateFlushCmd = &cli.Command{ Name: "flush", Usage: "Send a terminate message if there are sectors queued for termination", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - mcid, err := nodeApi.SectorTerminateFlush(ctx) + mcid, err := minerApi.SectorTerminateFlush(ctx) if err != nil { return err } @@ -1421,7 +1421,7 @@ var sectorsTerminatePendingCmd = &cli.Command{ Name: "pending", Usage: "List sector numbers of sectors pending termination", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -1433,12 +1433,12 @@ var sectorsTerminatePendingCmd = &cli.Command{ defer nCloser() ctx := lcli.ReqContext(cctx) - pending, err := nodeApi.SectorTerminatePending(ctx) + pending, err := minerAPI.SectorTerminatePending(ctx) if err != nil { return err } - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerAPI.ActorAddress(ctx) if err != nil { return err } @@ -1482,14 +1482,14 @@ var sectorsRemoveCmd = &cli.Command{ if !cctx.Bool("really-do-it") { return xerrors.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass sector number") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1497,7 +1497,7 @@ var sectorsRemoveCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - return nodeApi.SectorRemove(ctx, abi.SectorNumber(id)) + return minerAPI.SectorRemove(ctx, abi.SectorNumber(id)) }, } @@ -1506,11 +1506,11 @@ var sectorsSnapUpCmd = &cli.Command{ Usage: "Mark a committed capacity sector to be filled with deals", ArgsUsage: "", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number")) + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -1535,7 +1535,7 @@ var sectorsSnapUpCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - return nodeApi.SectorMarkForUpgrade(ctx, abi.SectorNumber(id), true) + return minerAPI.SectorMarkForUpgrade(ctx, abi.SectorNumber(id), true) }, } @@ -1550,7 +1550,7 @@ var sectorsSnapAbortCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { + if cctx.NArg() != 1 { return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number")) } @@ -1560,7 +1560,7 @@ var sectorsSnapAbortCmd = &cli.Command{ return fmt.Errorf("--really-do-it must be specified for this action to have an effect; you have been warned") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -1572,7 +1572,7 @@ var sectorsSnapAbortCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - return nodeApi.SectorAbortUpgrade(ctx, abi.SectorNumber(id)) + return minerAPI.SectorAbortUpgrade(ctx, abi.SectorNumber(id)) }, } @@ -1581,14 +1581,14 @@ var sectorsStartSealCmd = &cli.Command{ Usage: "Manually start sealing a sector (filling any unused space with junk)", ArgsUsage: "", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass sector number") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1596,7 +1596,7 @@ var sectorsStartSealCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - return nodeApi.SectorStartSealing(ctx, abi.SectorNumber(id)) + return minerAPI.SectorStartSealing(ctx, abi.SectorNumber(id)) }, } @@ -1605,14 +1605,14 @@ var sectorsSealDelayCmd = &cli.Command{ Usage: "Set the time, in minutes, that a new sector waits for deals before sealing starts", ArgsUsage: "", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 1 { - return xerrors.Errorf("must pass duration in minutes") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } hs, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1622,7 +1622,7 @@ var sectorsSealDelayCmd = &cli.Command{ delay := hs * uint64(time.Minute) - return nodeApi.SectorSetSealDelay(ctx, time.Duration(delay)) + return minerAPI.SectorSetSealDelay(ctx, time.Duration(delay)) }, } @@ -1708,14 +1708,14 @@ var sectorsUpdateCmd = &cli.Command{ if !cctx.Bool("really-do-it") { return xerrors.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() < 2 { - return xerrors.Errorf("must pass sector number and new state") + if cctx.NArg() < 2 { + return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number and new state")) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1723,7 +1723,7 @@ var sectorsUpdateCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - _, err = nodeApi.SectorsStatus(ctx, abi.SectorNumber(id), false) + _, err = minerAPI.SectorsStatus(ctx, abi.SectorNumber(id), false) if err != nil { return xerrors.Errorf("sector %d not found, could not change state", id) } @@ -1737,7 +1737,7 @@ var sectorsUpdateCmd = &cli.Command{ return nil } - return nodeApi.SectorsUpdate(ctx, abi.SectorNumber(id), api.SectorState(cctx.Args().Get(1))) + return minerAPI.SectorsUpdate(ctx, abi.SectorNumber(id), api.SectorState(cctx.Args().Get(1))) }, } @@ -1765,7 +1765,7 @@ var sectorsExpiredCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -1805,7 +1805,7 @@ var sectorsExpiredCmd = &cli.Command{ return xerrors.Errorf("getting lookback tipset: %w", err) } - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerAPI.ActorAddress(ctx) if err != nil { return xerrors.Errorf("getting actor address: %w", err) } @@ -1813,7 +1813,7 @@ var sectorsExpiredCmd = &cli.Command{ // toCheck is a working bitfield which will only contain terminated sectors toCheck := bitfield.New() { - sectors, err := nodeApi.SectorsList(ctx) + sectors, err := minerAPI.SectorsList(ctx) if err != nil { return xerrors.Errorf("getting sector list: %w", err) } @@ -1890,7 +1890,7 @@ var sectorsExpiredCmd = &cli.Command{ err = toCheck.ForEach(func(u uint64) error { s := abi.SectorNumber(u) - st, err := nodeApi.SectorsStatus(ctx, s, true) + st, err := minerAPI.SectorsStatus(ctx, s, true) if err != nil { fmt.Printf("%d:\tError getting status: %s\n", u, err) return nil @@ -1933,7 +1933,7 @@ var sectorsExpiredCmd = &cli.Command{ for _, number := range toRemove { fmt.Printf("Removing sector\t%s:\t", color.YellowString("%d", number)) - err := nodeApi.SectorRemove(ctx, number) + err := minerAPI.SectorRemove(ctx, number) if err != nil { color.Red("ERROR: %s\n", err.Error()) } else { @@ -1965,7 +1965,7 @@ var sectorsBatchingPendingCommit = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -1973,7 +1973,7 @@ var sectorsBatchingPendingCommit = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.Bool("publish-now") { - res, err := api.SectorCommitFlush(ctx) + res, err := minerAPI.SectorCommitFlush(ctx) if err != nil { return xerrors.Errorf("flush: %w", err) } @@ -2000,7 +2000,7 @@ var sectorsBatchingPendingCommit = &cli.Command{ return nil } - pending, err := api.SectorCommitPending(ctx) + pending, err := minerAPI.SectorCommitPending(ctx) if err != nil { return xerrors.Errorf("getting pending deals: %w", err) } @@ -2027,7 +2027,7 @@ var sectorsBatchingPendingPreCommit = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -2035,7 +2035,7 @@ var sectorsBatchingPendingPreCommit = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.Bool("publish-now") { - res, err := api.SectorPreCommitFlush(ctx) + res, err := minerAPI.SectorPreCommitFlush(ctx) if err != nil { return xerrors.Errorf("flush: %w", err) } @@ -2058,7 +2058,7 @@ var sectorsBatchingPendingPreCommit = &cli.Command{ return nil } - pending, err := api.SectorPreCommitPending(ctx) + pending, err := minerAPI.SectorPreCommitPending(ctx) if err != nil { return xerrors.Errorf("getting pending deals: %w", err) } @@ -2079,14 +2079,14 @@ var sectorsRefreshPieceMatchingCmd = &cli.Command{ Name: "match-pending-pieces", Usage: "force a refreshed match of pending pieces to open sectors without manually waiting for more deals", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if err := nodeApi.SectorMatchPendingPiecesToOpenSectors(ctx); err != nil { + if err := minerAPI.SectorMatchPendingPiecesToOpenSectors(ctx); err != nil { return err } @@ -2195,7 +2195,7 @@ var sectorsCompactPartitionsCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println(cctx.App.Writer, "compact partitions failed!") return err } @@ -2219,14 +2219,14 @@ var sectorsNumbersInfoCmd = &cli.Command{ Name: "info", Usage: "view sector assigner state", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - am, err := api.SectorNumAssignerMeta(ctx) + am, err := minerAPI.SectorNumAssignerMeta(ctx) if err != nil { return err } @@ -2253,14 +2253,14 @@ var sectorsNumbersReservationsCmd = &cli.Command{ Name: "reservations", Usage: "list sector number reservations", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - rs, err := api.SectorNumReservations(ctx) + rs, err := minerAPI.SectorNumReservations(ctx) if err != nil { return err } @@ -2303,15 +2303,15 @@ var sectorsNumbersReserveCmd = &cli.Command{ }, ArgsUsage: "[reservation name] [reserved ranges]", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 2 { - return xerrors.Errorf("expected 2 arguments: [reservation name] [reserved ranges]") + if cctx.NArg() != 2 { + return lcli.IncorrectNumArgs(cctx) } bf, err := strle.HumanRangesToBitField(cctx.Args().Get(1)) @@ -2319,7 +2319,7 @@ var sectorsNumbersReserveCmd = &cli.Command{ return xerrors.Errorf("parsing ranges: %w", err) } - return api.SectorNumReserve(ctx, cctx.Args().First(), bf, cctx.Bool("force")) + return minerAPI.SectorNumReserve(ctx, cctx.Args().First(), bf, cctx.Bool("force")) }, } @@ -2328,17 +2328,17 @@ var sectorsNumbersFreeCmd = &cli.Command{ Usage: "remove sector number reservations", ArgsUsage: "[reservation name]", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument: [reservation name]") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } - return api.SectorNumFree(ctx, cctx.Args().First()) + return minerAPI.SectorNumFree(ctx, cctx.Args().First()) }, } diff --git a/cmd/lotus-miner/storage.go b/cmd/lotus-miner/storage.go index cc5d94534..1200448b1 100644 --- a/cmd/lotus-miner/storage.go +++ b/cmd/lotus-miner/storage.go @@ -109,7 +109,7 @@ over time }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -172,7 +172,7 @@ over time } } - return nodeApi.StorageAddLocal(ctx, p) + return minerApi.StorageAddLocal(ctx, p) }, } @@ -186,7 +186,7 @@ var storageDetachCmd = &cli.Command{ }, ArgsUsage: "[path]", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -206,7 +206,7 @@ var storageDetachCmd = &cli.Command{ return xerrors.Errorf("pass --really-do-it to execute the action") } - return nodeApi.StorageDetachLocal(ctx, p) + return minerApi.StorageDetachLocal(ctx, p) }, } @@ -228,7 +228,7 @@ var storageRedeclareCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -241,11 +241,11 @@ var storageRedeclareCmd = &cli.Command{ if cctx.IsSet("id") { id := storiface.ID(cctx.String("id")) - return nodeApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing")) + return minerApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing")) } if cctx.Bool("all") { - return nodeApi.StorageRedeclareLocal(ctx, nil, cctx.Bool("drop-missing")) + return minerApi.StorageRedeclareLocal(ctx, nil, cctx.Bool("drop-missing")) } return xerrors.Errorf("either --all or --id must be specified") @@ -270,19 +270,19 @@ var storageListCmd = &cli.Command{ color.NoColor = !cctx.Bool("color") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - st, err := nodeApi.StorageList(ctx) + st, err := minerApi.StorageList(ctx) if err != nil { return err } - local, err := nodeApi.StorageLocal(ctx) + local, err := minerApi.StorageLocal(ctx) if err != nil { return err } @@ -295,7 +295,7 @@ var storageListCmd = &cli.Command{ sorted := make([]fsInfo, 0, len(st)) for id, decls := range st { - st, err := nodeApi.StorageStat(ctx, id) + st, err := minerApi.StorageStat(ctx, id) if err != nil { sorted = append(sorted, fsInfo{ID: id, sectors: decls}) continue @@ -325,7 +325,7 @@ var storageListCmd = &cli.Command{ fmt.Printf("%s:\n", s.ID) pingStart := time.Now() - st, err := nodeApi.StorageStat(ctx, s.ID) + st, err := minerApi.StorageStat(ctx, s.ID) if err != nil { fmt.Printf("\t%s: %s:\n", color.RedString("Error"), err) continue @@ -398,7 +398,7 @@ var storageListCmd = &cli.Command{ color.BlueString("Caches: %d", cnt[2]), types.SizeStr(types.NewInt(uint64(st.Reserved)))) - si, err := nodeApi.StorageInfo(ctx, s.ID) + si, err := minerApi.StorageInfo(ctx, s.ID) if err != nil { return err } @@ -469,14 +469,14 @@ var storageFindCmd = &cli.Command{ Usage: "find sector in the storage system", ArgsUsage: "[sector number]", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - ma, err := nodeApi.ActorAddress(ctx) + ma, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -500,27 +500,27 @@ var storageFindCmd = &cli.Command{ Number: abi.SectorNumber(snum), } - u, err := nodeApi.StorageFindSector(ctx, sid, storiface.FTUnsealed, 0, false) + u, err := minerApi.StorageFindSector(ctx, sid, storiface.FTUnsealed, 0, false) if err != nil { return xerrors.Errorf("finding unsealed: %w", err) } - s, err := nodeApi.StorageFindSector(ctx, sid, storiface.FTSealed, 0, false) + s, err := minerApi.StorageFindSector(ctx, sid, storiface.FTSealed, 0, false) if err != nil { return xerrors.Errorf("finding sealed: %w", err) } - c, err := nodeApi.StorageFindSector(ctx, sid, storiface.FTCache, 0, false) + c, err := minerApi.StorageFindSector(ctx, sid, storiface.FTCache, 0, false) if err != nil { return xerrors.Errorf("finding cache: %w", err) } - us, err := nodeApi.StorageFindSector(ctx, sid, storiface.FTUpdate, 0, false) + us, err := minerApi.StorageFindSector(ctx, sid, storiface.FTUpdate, 0, false) if err != nil { return xerrors.Errorf("finding sealed: %w", err) } - uc, err := nodeApi.StorageFindSector(ctx, sid, storiface.FTUpdateCache, 0, false) + uc, err := minerApi.StorageFindSector(ctx, sid, storiface.FTUpdateCache, 0, false) if err != nil { return xerrors.Errorf("finding cache: %w", err) } @@ -582,7 +582,7 @@ var storageFindCmd = &cli.Command{ sts.updatecache = true } - local, err := nodeApi.StorageLocal(ctx) + local, err := minerApi.StorageLocal(ctx) if err != nil { return err } @@ -644,7 +644,7 @@ var storageListSectorsCmd = &cli.Command{ color.NoColor = !cctx.Bool("color") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -658,12 +658,12 @@ var storageListSectorsCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - sectors, err := nodeApi.SectorsList(ctx) + sectors, err := minerApi.SectorsList(ctx) if err != nil { return xerrors.Errorf("listing sectors: %w", err) } - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := minerApi.ActorAddress(ctx) if err != nil { return err } @@ -706,7 +706,7 @@ var storageListSectorsCmd = &cli.Command{ var list []entry for _, sector := range sectors { - st, err := nodeApi.SectorsStatus(ctx, sector, false) + st, err := minerApi.SectorsStatus(ctx, sector, false) if err != nil { return xerrors.Errorf("getting sector status for sector %d: %w", sector, err) } @@ -716,7 +716,7 @@ var storageListSectorsCmd = &cli.Command{ } for _, ft := range storiface.PathTypes { - si, err := nodeApi.StorageFindSector(ctx, sid(sector), ft, mi.SectorSize, false) + si, err := minerApi.StorageFindSector(ctx, sid(sector), ft, mi.SectorSize, false) if err != nil { return xerrors.Errorf("find sector %d: %w", sector, err) } @@ -869,7 +869,7 @@ var storageCleanupCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -884,7 +884,7 @@ var storageCleanupCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.Bool("removed") { - if err := cleanupRemovedSectorData(ctx, api, napi); err != nil { + if err := cleanupRemovedSectorData(ctx, minerAPI, napi); err != nil { return err } } @@ -962,20 +962,20 @@ var storageLocks = &cli.Command{ Name: "locks", Usage: "show active sector locks", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() ctx := lcli.ReqContext(cctx) - locks, err := api.StorageGetLocks(ctx) + locks, err := minerAPI.StorageGetLocks(ctx) if err != nil { return err } for _, lock := range locks.Locks { - st, err := api.SectorsStatus(ctx, lock.Sector.Number, false) + st, err := minerAPI.SectorsStatus(ctx, lock.Sector.Number, false) if err != nil { return xerrors.Errorf("getting sector status(%d): %w", lock.Sector.Number, err) } diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index 9f0a8f7dc..df2a91ad9 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -93,7 +93,7 @@ var genesisAddMinerCmd = &cli.Command{ Description: "add genesis miner", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { + if cctx.NArg() != 2 { return xerrors.New("seed genesis add-miner [genesis.json] [preseal.json]") } @@ -181,7 +181,7 @@ type GenAccountEntry struct { var genesisAddMsigsCmd = &cli.Command{ Name: "add-msigs", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 2 { + if cctx.NArg() < 2 { return fmt.Errorf("must specify template file and csv file with accounts") } @@ -329,7 +329,7 @@ var genesisSetVRKCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { + if cctx.NArg() != 1 { return fmt.Errorf("must specify template file") } @@ -425,7 +425,7 @@ var genesisSetRemainderCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { + if cctx.NArg() != 1 { return fmt.Errorf("must specify template file") } @@ -519,7 +519,7 @@ var genesisSetActorVersionCmd = &cli.Command{ }, ArgsUsage: "", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { + if cctx.NArg() != 1 { return fmt.Errorf("must specify genesis file") } @@ -597,7 +597,7 @@ var genesisSetVRKSignersCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { + if cctx.NArg() != 1 { return fmt.Errorf("must specify template file") } diff --git a/cmd/lotus-shed/actor.go b/cmd/lotus-shed/actor.go index c07b50ffb..9d1fd9d19 100644 --- a/cmd/lotus-shed/actor.go +++ b/cmd/lotus-shed/actor.go @@ -74,13 +74,13 @@ var actorWithdrawCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if maddr.Empty() { - minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - maddr, err = minerAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -144,7 +144,7 @@ var actorWithdrawCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println(cctx.App.Writer, "withdrawal failed!") return err } @@ -192,7 +192,7 @@ var actorSetOwnerCmd = &cli.Command{ } if cctx.NArg() != 2 { - return fmt.Errorf("must pass new owner address and sender address") + return lcli.IncorrectNumArgs(cctx) } var maddr address.Address @@ -233,13 +233,13 @@ var actorSetOwnerCmd = &cli.Command{ } if maddr.Empty() { - minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - maddr, err = minerAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -279,7 +279,7 @@ var actorSetOwnerCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println("owner change failed!") return err } @@ -339,13 +339,13 @@ var actorControlList = &cli.Command{ ctx := lcli.ReqContext(cctx) if maddr.Empty() { - minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - maddr, err = minerAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -448,13 +448,13 @@ var actorControlSet = &cli.Command{ ctx := lcli.ReqContext(cctx) if maddr.Empty() { - minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - maddr, err = minerAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -590,13 +590,13 @@ var actorProposeChangeWorker = &cli.Command{ } if maddr.Empty() { - minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - maddr, err = minerAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -647,7 +647,7 @@ var actorProposeChangeWorker = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose worker change failed!") return err } @@ -720,13 +720,13 @@ var actorConfirmChangeWorker = &cli.Command{ } if maddr.Empty() { - minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - maddr, err = minerAPI.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -768,7 +768,7 @@ var actorConfirmChangeWorker = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Worker change failed!") return err } diff --git a/cmd/lotus-shed/base16.go b/cmd/lotus-shed/base16.go index adfdfeddb..a5d384815 100644 --- a/cmd/lotus-shed/base16.go +++ b/cmd/lotus-shed/base16.go @@ -24,7 +24,7 @@ var base16Cmd = &cli.Command{ Action: func(cctx *cli.Context) error { var input io.Reader - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { input = os.Stdin } else { input = strings.NewReader(cctx.Args().First()) diff --git a/cmd/lotus-shed/base32.go b/cmd/lotus-shed/base32.go index 4ca177316..66e180ddc 100644 --- a/cmd/lotus-shed/base32.go +++ b/cmd/lotus-shed/base32.go @@ -24,7 +24,7 @@ var base32Cmd = &cli.Command{ Action: func(cctx *cli.Context) error { var input io.Reader - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { input = os.Stdin } else { input = strings.NewReader(cctx.Args().First()) diff --git a/cmd/lotus-shed/base64.go b/cmd/lotus-shed/base64.go index 9143a6a19..cacc60152 100644 --- a/cmd/lotus-shed/base64.go +++ b/cmd/lotus-shed/base64.go @@ -32,7 +32,7 @@ var base64Cmd = &cli.Command{ Action: func(cctx *cli.Context) error { var input io.Reader - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { input = os.Stdin } else { input = strings.NewReader(cctx.Args().First()) diff --git a/cmd/lotus-shed/chain.go b/cmd/lotus-shed/chain.go index efbbd3b62..9eaa42795 100644 --- a/cmd/lotus-shed/chain.go +++ b/cmd/lotus-shed/chain.go @@ -56,7 +56,7 @@ var computeStateRangeCmd = &cli.Command{ ArgsUsage: "[START_TIPSET_REF] [END_TIPSET_REF]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return fmt.Errorf("expected two arguments: a start and an end tipset") + return lcli.IncorrectNumArgs(cctx) } api, closer, err := lcli.GetFullNodeAPI(cctx) diff --git a/cmd/lotus-shed/consensus.go b/cmd/lotus-shed/consensus.go index f6bd7688f..197de56f9 100644 --- a/cmd/lotus-shed/consensus.go +++ b/cmd/lotus-shed/consensus.go @@ -84,7 +84,7 @@ var consensusCheckCmd = &cli.Command{ filePath := cctx.Args().First() var input *bufio.Reader - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { input = bufio.NewReader(os.Stdin) } else { var err error diff --git a/cmd/lotus-shed/datastore.go b/cmd/lotus-shed/datastore.go index 7cdb2b1e6..5614e34f6 100644 --- a/cmd/lotus-shed/datastore.go +++ b/cmd/lotus-shed/datastore.go @@ -20,6 +20,7 @@ import ( "go.uber.org/multierr" "golang.org/x/xerrors" + lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/backupds" "github.com/filecoin-project/lotus/node/repo" ) @@ -171,8 +172,8 @@ var datastoreBackupStatCmd = &cli.Command{ Description: "validate and print info about datastore backup", ArgsUsage: "[file]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } f, err := os.Open(cctx.Args().First()) @@ -220,8 +221,8 @@ var datastoreBackupListCmd = &cli.Command{ }, ArgsUsage: "[file]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } f, err := os.Open(cctx.Args().First()) @@ -308,7 +309,7 @@ var datastoreRewriteCmd = &cli.Command{ ArgsUsage: "source destination", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return xerrors.Errorf("expected 2 arguments, got %d", cctx.NArg()) + return lcli.IncorrectNumArgs(cctx) } fromPath, err := homedir.Expand(cctx.Args().Get(0)) if err != nil { diff --git a/cmd/lotus-shed/diff.go b/cmd/lotus-shed/diff.go index 9fc6f7963..22b54981f 100644 --- a/cmd/lotus-shed/diff.go +++ b/cmd/lotus-shed/diff.go @@ -31,7 +31,7 @@ var diffStateTrees = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() != 2 { - return xerrors.Errorf("expected two state-tree roots") + return lcli.IncorrectNumArgs(cctx) } argA := cctx.Args().Get(0) diff --git a/cmd/lotus-shed/export-car.go b/cmd/lotus-shed/export-car.go index 97e4fb6c6..214b1d5df 100644 --- a/cmd/lotus-shed/export-car.go +++ b/cmd/lotus-shed/export-car.go @@ -38,8 +38,8 @@ var exportCarCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return lcli.ShowHelp(cctx, fmt.Errorf("must specify file name and object")) + if cctx.NArg() != 2 { + return lcli.IncorrectNumArgs(cctx) } outfile := cctx.Args().First() diff --git a/cmd/lotus-shed/keyinfo.go b/cmd/lotus-shed/keyinfo.go index 135b5bc9d..373964dc6 100644 --- a/cmd/lotus-shed/keyinfo.go +++ b/cmd/lotus-shed/keyinfo.go @@ -149,7 +149,7 @@ var keyinfoImportCmd = &cli.Command{ flagRepo := cctx.String("repo") var input io.Reader - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { input = os.Stdin } else { var err error @@ -261,7 +261,7 @@ var keyinfoInfoCmd = &cli.Command{ format := cctx.String("format") var input io.Reader - if cctx.Args().Len() == 0 { + if cctx.NArg() == 0 { input = os.Stdin } else { var err error diff --git a/cmd/lotus-shed/ledger.go b/cmd/lotus-shed/ledger.go index 20de8dd89..d9a888d20 100644 --- a/cmd/lotus-shed/ledger.go +++ b/cmd/lotus-shed/ledger.go @@ -300,7 +300,7 @@ var ledgerNewAddressesCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return fmt.Errorf("must pass account index") + return lcli.IncorrectNumArgs(cctx) } index, err := strconv.ParseUint(cctx.Args().First(), 10, 32) diff --git a/cmd/lotus-shed/migrations.go b/cmd/lotus-shed/migrations.go index 2c75edd74..2e291c947 100644 --- a/cmd/lotus-shed/migrations.go +++ b/cmd/lotus-shed/migrations.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" + lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" ) @@ -34,7 +35,7 @@ var migrationsCmd = &cli.Command{ ctx := context.TODO() if cctx.NArg() != 1 { - return fmt.Errorf("must pass block cid") + return lcli.IncorrectNumArgs(cctx) } blkCid, err := cid.Decode(cctx.Args().First()) diff --git a/cmd/lotus-shed/miner-multisig.go b/cmd/lotus-shed/miner-multisig.go index aba08113f..e4268a291 100644 --- a/cmd/lotus-shed/miner-multisig.go +++ b/cmd/lotus-shed/miner-multisig.go @@ -101,7 +101,7 @@ var mmProposeWithdrawBalance = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose owner change tx failed!") return err } @@ -128,7 +128,7 @@ var mmApproveWithdrawBalance = &cli.Command{ ArgsUsage: "[amount txnId proposer]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return fmt.Errorf("must pass amount, txn Id, and proposer address") + return lcli.IncorrectNumArgs(cctx) } api, closer, err := lcli.GetFullNodeAPI(cctx) @@ -180,7 +180,7 @@ var mmApproveWithdrawBalance = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Approve owner change tx failed!") return err } @@ -261,7 +261,7 @@ var mmProposeChangeOwner = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose owner change tx failed!") return err } @@ -287,7 +287,7 @@ var mmApproveChangeOwner = &cli.Command{ ArgsUsage: "[newOwner txnId proposer]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return fmt.Errorf("must pass new owner address, txn Id, and proposer address") + return lcli.IncorrectNumArgs(cctx) } api, closer, err := lcli.GetFullNodeAPI(cctx) @@ -351,7 +351,7 @@ var mmApproveChangeOwner = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Approve owner change tx failed!") return err } @@ -448,7 +448,7 @@ var mmProposeChangeWorker = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose worker change tx failed!") return err } @@ -532,7 +532,7 @@ var mmConfirmChangeWorker = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose worker change tx failed!") return err } @@ -647,7 +647,7 @@ var mmProposeControlSet = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Fprintln(cctx.App.Writer, "Propose worker change tx failed!") return err } diff --git a/cmd/lotus-shed/miner-peerid.go b/cmd/lotus-shed/miner-peerid.go index 85f720a10..e43063797 100644 --- a/cmd/lotus-shed/miner-peerid.go +++ b/cmd/lotus-shed/miner-peerid.go @@ -20,6 +20,7 @@ import ( "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" + lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/node/repo" ) @@ -35,7 +36,7 @@ var minerPeeridCmd = &cli.Command{ ctx := context.TODO() if cctx.NArg() != 2 { - return fmt.Errorf("must pass peer id and state root") + return lcli.IncorrectNumArgs(cctx) } pid, err := peer.Decode(cctx.Args().Get(0)) diff --git a/cmd/lotus-shed/miner.go b/cmd/lotus-shed/miner.go index a23a44410..348626fe1 100644 --- a/cmd/lotus-shed/miner.go +++ b/cmd/lotus-shed/miner.go @@ -135,8 +135,8 @@ var minerCreateCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() != 4 { - return xerrors.Errorf("expected 4 args (sender owner worker sectorSize)") + if cctx.NArg() != 4 { + return lcli.IncorrectNumArgs(cctx) } sender, err := address.NewFromString(cctx.Args().First()) @@ -273,8 +273,8 @@ var minerUnpackInfoCmd = &cli.Command{ Usage: "unpack miner info all dump", ArgsUsage: "[allinfo.txt] [dir]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 2 { - return xerrors.Errorf("expected 2 args") + if cctx.NArg() != 2 { + return lcli.IncorrectNumArgs(cctx) } src, err := homedir.Expand(cctx.Args().Get(0)) @@ -475,7 +475,7 @@ var sendInvalidWindowPoStCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println(cctx.App.Writer, "Invalid PoST message failed!") return err } @@ -488,9 +488,10 @@ var generateAndSendConsensusFaultCmd = &cli.Command{ Name: "generate-and-send-consensus-fault", Usage: "Provided a block CID mined by the miner, will create another block at the same height, and send both block headers to generate a consensus fault.", Description: `Note: This is meant for testing purposes and should NOT be used on mainnet or you will be slashed`, + ArgsUsage: "blockCID", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 arg (blockCID)") + return lcli.IncorrectNumArgs(cctx) } blockCid, err := cid.Parse(cctx.Args().First()) @@ -574,7 +575,7 @@ var generateAndSendConsensusFaultCmd = &cli.Command{ } // check it executed successfully - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { fmt.Println(cctx.App.Writer, "Report consensus fault failed!") return err } diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 49412948c..847b93d9f 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -27,8 +27,8 @@ var msgCmd = &cli.Command{ Usage: "Translate message between various formats", ArgsUsage: "Message in any form", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("expected 1 argument") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } msg, err := messageFromString(cctx, cctx.Args().First()) diff --git a/cmd/lotus-shed/proofs.go b/cmd/lotus-shed/proofs.go index 65cf04918..1a16e2fdc 100644 --- a/cmd/lotus-shed/proofs.go +++ b/cmd/lotus-shed/proofs.go @@ -11,6 +11,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" prooftypes "github.com/filecoin-project/go-state-types/proof" + + lcli "github.com/filecoin-project/lotus/cli" ) var proofsCmd = &cli.Command{ @@ -42,8 +44,8 @@ var verifySealProofCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return fmt.Errorf("must specify commR, commD, and proof to verify") + if cctx.NArg() != 3 { + return lcli.IncorrectNumArgs(cctx) } commr, err := cid.Decode(cctx.Args().Get(0)) diff --git a/cmd/lotus-shed/rpc.go b/cmd/lotus-shed/rpc.go index b253304a1..3be269358 100644 --- a/cmd/lotus-shed/rpc.go +++ b/cmd/lotus-shed/rpc.go @@ -112,8 +112,8 @@ var rpcCmd = &cli.Command{ } if cctx.Args().Present() { - if cctx.Args().Len() > 2 { - return xerrors.Errorf("expected 1 or 2 arguments: method [params]") + if cctx.NArg() > 2 { + return lcli.ShowHelp(cctx, xerrors.Errorf("expected 1 or 2 arguments: method [params]")) } params := cctx.Args().Get(1) diff --git a/cmd/lotus-shed/sectors.go b/cmd/lotus-shed/sectors.go index 0332b4ba3..52d07f5b6 100644 --- a/cmd/lotus-shed/sectors.go +++ b/cmd/lotus-shed/sectors.go @@ -64,8 +64,8 @@ var terminateSectorCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 1 { - return fmt.Errorf("at least one sector must be specified") + if cctx.NArg() < 1 { + return lcli.ShowHelp(cctx, fmt.Errorf("at least one sector must be specified")) } var maddr address.Address @@ -90,13 +90,13 @@ var terminateSectorCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if maddr.Empty() { - api, acloser, err := lcli.GetStorageMinerAPI(cctx) + minerApi, acloser, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer acloser() - maddr, err = api.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } @@ -171,7 +171,7 @@ var terminateSectorCmd = &cli.Command{ return err } - if wait.Receipt.ExitCode != 0 { + if wait.Receipt.ExitCode.IsError() { return fmt.Errorf("terminate sectors message returned exit %d", wait.Receipt.ExitCode) } @@ -200,8 +200,8 @@ var terminateSectorPenaltyEstimationCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 1 { - return fmt.Errorf("at least one sector must be specified") + if cctx.NArg() < 1 { + return lcli.ShowHelp(cctx, fmt.Errorf("at least one sector must be specified")) } var maddr address.Address @@ -222,13 +222,13 @@ var terminateSectorPenaltyEstimationCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if maddr.Empty() { - api, acloser, err := lcli.GetStorageMinerAPI(cctx) + minerApi, acloser, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer acloser() - maddr, err = api.ActorAddress(ctx) + maddr, err = minerApi.ActorAddress(ctx) if err != nil { return err } diff --git a/cmd/lotus-shed/send-csv.go b/cmd/lotus-shed/send-csv.go index ce1c8b68a..17b62150f 100644 --- a/cmd/lotus-shed/send-csv.go +++ b/cmd/lotus-shed/send-csv.go @@ -34,7 +34,7 @@ var sendCsvCmd = &cli.Command{ ArgsUsage: "[csvfile]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.New("must supply path to csv file") + return lcli.IncorrectNumArgs(cctx) } api, closer, err := lcli.GetFullNodeAPIV1(cctx) diff --git a/cmd/lotus-shed/signatures.go b/cmd/lotus-shed/signatures.go index 0f43503f6..536f8e82d 100644 --- a/cmd/lotus-shed/signatures.go +++ b/cmd/lotus-shed/signatures.go @@ -31,8 +31,8 @@ var sigsVerifyBlsMsgsCmd = &cli.Command{ Description: "given a block, verifies the bls signature of the messages in the block", Usage: "", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return xerrors.Errorf("usage: ") + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) } api, closer, err := lcli.GetFullNodeAPI(cctx) @@ -101,8 +101,8 @@ var sigsVerifyVoteCmd = &cli.Command{ Usage: " ", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return xerrors.Errorf("usage: verify-vote ") + if cctx.NArg() != 3 { + return lcli.IncorrectNumArgs(cctx) } fip, err := strconv.ParseInt(cctx.Args().First(), 10, 64) diff --git a/cmd/lotus-shed/stateroot-stats.go b/cmd/lotus-shed/stateroot-stats.go index 7937b3ccd..f429c4e64 100644 --- a/cmd/lotus-shed/stateroot-stats.go +++ b/cmd/lotus-shed/stateroot-stats.go @@ -174,8 +174,8 @@ var staterootStatCmd = &cli.Command{ } outcap := 10 - if cctx.Args().Len() > outcap { - outcap = cctx.Args().Len() + if cctx.NArg() > outcap { + outcap = cctx.NArg() } if len(infos) < outcap { outcap = len(infos) diff --git a/cmd/lotus-shed/sync.go b/cmd/lotus-shed/sync.go index 397e76da3..eb11dea27 100644 --- a/cmd/lotus-shed/sync.go +++ b/cmd/lotus-shed/sync.go @@ -38,10 +38,8 @@ var syncValidateCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() < 1 { - fmt.Println("usage: ...") - fmt.Println("At least one block cid must be provided") - return nil + if cctx.NArg() < 1 { + return lcli.ShowHelp(cctx, fmt.Errorf("at least one block cid must be provided")) } args := cctx.Args().Slice() @@ -75,7 +73,7 @@ var syncScrapePowerCmd = &cli.Command{ Usage: "given a height and a tipset, reports what percentage of mining power had a winning ticket between the tipset and height", ArgsUsage: "[height tipsetkey]", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 1 { + if cctx.NArg() < 1 { fmt.Println("usage: [blockCid1 blockCid2...]") fmt.Println("Any CIDs passed after the height will be used as the tipset key") fmt.Println("If no block CIDs are provided, chain head will be used") @@ -90,10 +88,8 @@ var syncScrapePowerCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - if cctx.Args().Len() < 1 { - fmt.Println("usage: ...") - fmt.Println("At least one block cid must be provided") - return nil + if cctx.NArg() < 1 { + return lcli.ShowHelp(cctx, fmt.Errorf("at least one block cid must be provided")) } h, err := strconv.ParseInt(cctx.Args().Get(0), 10, 0) diff --git a/cmd/lotus-shed/terminations.go b/cmd/lotus-shed/terminations.go index 87855cec7..c5f35995a 100644 --- a/cmd/lotus-shed/terminations.go +++ b/cmd/lotus-shed/terminations.go @@ -23,6 +23,7 @@ import ( "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" + lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/node/repo" ) @@ -40,7 +41,7 @@ var terminationsCmd = &cli.Command{ ctx := context.TODO() if cctx.NArg() != 2 { - return fmt.Errorf("must pass block cid && lookback period") + return lcli.IncorrectNumArgs(cctx) } blkCid, err := cid.Decode(cctx.Args().First()) diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index 2731ea11b..0fa905b5f 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -46,8 +46,8 @@ var verifRegAddVerifierFromMsigCmd = &cli.Command{ Usage: "make a given account a verifier", ArgsUsage: " ", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return fmt.Errorf("must specify three arguments: sender, verifier, and allowance") + if cctx.NArg() != 3 { + return lcli.IncorrectNumArgs(cctx) } sender, err := address.NewFromString(cctx.Args().Get(0)) @@ -104,7 +104,7 @@ var verifRegAddVerifierFromMsigCmd = &cli.Command{ return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("failed to add verifier: %d", mwait.Receipt.ExitCode) } @@ -119,8 +119,8 @@ var verifRegAddVerifierFromAccountCmd = &cli.Command{ Usage: "make a given account a verifier", ArgsUsage: " ", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 3 { - return fmt.Errorf("must specify three arguments: sender, verifier, and allowance") + if cctx.NArg() != 3 { + return lcli.IncorrectNumArgs(cctx) } sender, err := address.NewFromString(cctx.Args().Get(0)) @@ -170,7 +170,7 @@ var verifRegAddVerifierFromAccountCmd = &cli.Command{ return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("failed to add verified client: %d", mwait.Receipt.ExitCode) } @@ -201,8 +201,8 @@ var verifRegVerifyClientCmd = &cli.Command{ return err } - if cctx.Args().Len() != 2 { - return fmt.Errorf("must specify two arguments: address and allowance") + if cctx.NArg() != 2 { + return lcli.IncorrectNumArgs(cctx) } target, err := address.NewFromString(cctx.Args().Get(0)) @@ -246,7 +246,7 @@ var verifRegVerifyClientCmd = &cli.Command{ return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("failed to add verified client: %d", mwait.Receipt.ExitCode) } @@ -418,8 +418,8 @@ var verifRegRemoveVerifiedClientDataCapCmd = &cli.Command{ Usage: "Remove data cap from verified client", ArgsUsage: " ", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 7 { - return fmt.Errorf("must specify seven arguments: sender, client, allowance to remove, verifier 1 address, verifier 1 signature, verifier 2 address, verifier 2 signature") + if cctx.NArg() != 7 { + return lcli.IncorrectNumArgs(cctx) } srv, err := lcli.GetFullNodeServices(cctx) @@ -555,7 +555,7 @@ var verifRegRemoveVerifiedClientDataCapCmd = &cli.Command{ return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { return fmt.Errorf("failed to removed verified data cap: %d", mwait.Receipt.ExitCode) } diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 6b2aee2aa..6d6b78a71 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -537,7 +537,7 @@ func (ca *channelAccessor) waitPaychCreateMsg(ctx context.Context, channelID str } // If channel creation failed - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { ca.lk.Lock() defer ca.lk.Unlock() @@ -651,7 +651,7 @@ func (ca *channelAccessor) waitAddFundsMsg(ctx context.Context, channelID string return err } - if mwait.Receipt.ExitCode != 0 { + if mwait.Receipt.ExitCode.IsError() { err := xerrors.Errorf("voucher channel creation failed: adding funds (exit code %d)", mwait.Receipt.ExitCode) log.Error(err)