diff --git a/cli/backup.go b/cli/backup.go index 3cb44718f..83234a423 100644 --- a/cli/backup.go +++ b/cli/backup.go @@ -115,7 +115,7 @@ this command must be within this base path`, ArgsUsage: "[backup file path]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + return IncorrectNumArgs(cctx) } if cctx.Bool("offline") { diff --git a/cli/chain.go b/cli/chain.go index 80df5655b..814aebeed 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -947,7 +947,7 @@ var ChainBisectCmd = &cli.Command{ ctx := ReqContext(cctx) if cctx.NArg() < 4 { - return xerrors.New("need at least 4 args") + return IncorrectNumArgs(cctx) } start, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1313,7 +1313,7 @@ var chainDecodeParamsCmd = &cli.Command{ ctx := ReqContext(cctx) if cctx.NArg() != 3 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + return IncorrectNumArgs(cctx) } to, err := address.NewFromString(cctx.Args().First()) @@ -1392,7 +1392,7 @@ var chainEncodeParamsCmd = &cli.Command{ afmt := NewAppFmt(cctx.App) if cctx.NArg() != 3 { - return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) + return IncorrectNumArgs(cctx) } method, err := strconv.ParseInt(cctx.Args().Get(1), 10, 64) diff --git a/cli/client.go b/cli/client.go index 577a8e840..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()) @@ -213,7 +213,7 @@ var clientCommPCmd = &cli.Command{ ctx := ReqContext(cctx) if cctx.NArg() != 1 { - return fmt.Errorf("usage: commP ") + return IncorrectNumArgs(cctx) } ret, err := api.ClientCalcCommP(ctx, cctx.Args().Get(0)) @@ -246,7 +246,7 @@ var clientCarGenCmd = &cli.Command{ ctx := ReqContext(cctx) if cctx.NArg() != 2 { - return fmt.Errorf("usage: generate-car ") + 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 5e19e5b04..d74171dd6 100644 --- a/cli/filplus.go +++ b/cli/filplus.go @@ -62,7 +62,7 @@ var filplusVerifyClientCmd = &cli.Command{ } if cctx.NArg() != 2 { - return fmt.Errorf("must specify two arguments: address and allowance") + return IncorrectNumArgs(cctx) } target, err := address.NewFromString(cctx.Args().Get(0)) @@ -290,7 +290,7 @@ var filplusSignRemoveDataCapProposal = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return fmt.Errorf("must specify three arguments: notary address, client address, and allowance to remove") + 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 c8003092d..e098806cb 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -611,7 +611,7 @@ var MpoolConfig = &cli.Command{ ArgsUsage: "[new-config]", Action: func(cctx *cli.Context) error { if cctx.NArg() > 1 { - return cli.ShowCommandHelp(cctx, cctx.Command.Name) + return IncorrectNumArgs(cctx) } afmt := NewAppFmt(cctx.App) diff --git a/cli/multisig.go b/cli/multisig.go index dc468a2cd..1dd7d01b8 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -89,7 +89,7 @@ var msigCreateCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() < 1 { - return ShowHelp(cctx, fmt.Errorf("multisigs must have at least one signer")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -754,7 +754,7 @@ var msigRemoveProposeCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address and signer address")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -841,7 +841,7 @@ var msigAddProposeCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address and signer address")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -950,7 +950,7 @@ var msigAddApproveCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 5 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, transaction id, new signer address, whether to increase threshold")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1041,7 +1041,7 @@ var msigAddCancelCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 4 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, transaction id, new signer address, whether to increase threshold")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1127,7 +1127,7 @@ var msigSwapProposeCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, old signer address, new signer address")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1208,7 +1208,7 @@ var msigSwapApproveCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 5 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, transaction id, old signer address, new signer address")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1299,7 +1299,7 @@ var msigSwapCancelCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 4 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, transaction id, old signer address, new signer address")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1385,7 +1385,7 @@ var msigLockProposeCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 4 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, start epoch, unlock duration, and amount")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1481,7 +1481,7 @@ var msigLockApproveCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 6 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, tx id, start epoch, unlock duration, and amount")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1587,7 +1587,7 @@ var msigLockCancelCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 5 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address, tx id, start epoch, unlock duration, and amount")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) @@ -1694,7 +1694,7 @@ var msigVestedCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address")) + return IncorrectNumArgs(cctx) } api, closer, err := GetFullNodeAPI(cctx) @@ -1750,7 +1750,7 @@ var msigProposeThresholdCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass multisig address and new threshold value")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) diff --git a/cli/net.go b/cli/net.go index c1ca1ce18..b0615e0b1 100644 --- a/cli/net.go +++ b/cli/net.go @@ -142,7 +142,7 @@ var NetPing = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("please provide a peerID") + return IncorrectNumArgs(cctx) } api, closer, err := GetAPI(cctx) diff --git a/cli/paych.go b/cli/paych.go index 09d4fcb11..1067d0913 100644 --- a/cli/paych.go +++ b/cli/paych.go @@ -51,7 +51,7 @@ var paychAddFundsCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return ShowHelp(cctx, fmt.Errorf("must pass three arguments: ")) + return IncorrectNumArgs(cctx) } from, err := address.NewFromString(cctx.Args().Get(0)) @@ -113,7 +113,7 @@ var paychStatusByFromToCmd = &cli.Command{ ArgsUsage: "[fromAddress toAddress]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass two arguments: ")) + return IncorrectNumArgs(cctx) } ctx := ReqContext(cctx) @@ -149,7 +149,7 @@ var paychStatusCmd = &cli.Command{ ArgsUsage: "[channelAddress]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass an argument: ")) + return IncorrectNumArgs(cctx) } ctx := ReqContext(cctx) @@ -261,7 +261,7 @@ var paychSettleCmd = &cli.Command{ ArgsUsage: "[channelAddress]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return fmt.Errorf("must pass payment channel address") + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -301,7 +301,7 @@ var paychCloseCmd = &cli.Command{ ArgsUsage: "[channelAddress]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return fmt.Errorf("must pass payment channel address") + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -361,7 +361,7 @@ var paychVoucherCreateCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass two arguments: ")) + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -409,7 +409,7 @@ var paychVoucherCheckCmd = &cli.Command{ ArgsUsage: "[channelAddress voucher]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher to validate")) + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -445,7 +445,7 @@ var paychVoucherAddCmd = &cli.Command{ ArgsUsage: "[channelAddress voucher]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher")) + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -487,7 +487,7 @@ var paychVoucherListCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address")) + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -532,7 +532,7 @@ var paychVoucherBestSpendableCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address")) + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) @@ -603,7 +603,7 @@ var paychVoucherSubmitCmd = &cli.Command{ ArgsUsage: "[channelAddress voucher]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher")) + return IncorrectNumArgs(cctx) } ch, err := address.NewFromString(cctx.Args().Get(0)) diff --git a/cli/send.go b/cli/send.go index b2471e7cd..4268f8eb2 100644 --- a/cli/send.go +++ b/cli/send.go @@ -68,7 +68,7 @@ var sendCmd = &cli.Command{ } if cctx.NArg() != 2 { - return ShowHelp(cctx, fmt.Errorf("'send' expects two arguments, target and amount")) + return IncorrectNumArgs(cctx) } srv, err := GetFullNodeServices(cctx) diff --git a/cli/state.go b/cli/state.go index e4afc6915..a7e195b1c 100644 --- a/cli/state.go +++ b/cli/state.go @@ -505,8 +505,7 @@ var StateReplayCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - fmt.Println("must provide cid of message to replay") - return nil + return IncorrectNumArgs(cctx) } mcid, err := cid.Decode(cctx.Args().First()) @@ -1581,7 +1580,7 @@ var StateCallCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() < 2 { - return fmt.Errorf("must specify at least actor and method to invoke") + return ShowHelp(cctx, fmt.Errorf("must specify at least actor and method to invoke")) } api, closer, err := GetFullNodeAPI(cctx) @@ -1744,7 +1743,7 @@ var StateSectorCmd = &cli.Command{ ctx := ReqContext(cctx) if cctx.NArg() != 2 { - return xerrors.Errorf("expected 2 params: minerAddress and sectorNumber") + return IncorrectNumArgs(cctx) } ts, err := LoadTipSet(ctx, cctx, api) diff --git a/cmd/lotus-miner/actor.go b/cmd/lotus-miner/actor.go index c06711170..aad110414 100644 --- a/cmd/lotus-miner/actor.go +++ b/cmd/lotus-miner/actor.go @@ -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) 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/init_restore.go b/cmd/lotus-miner/init_restore.go index 9d7f977b6..3d179f3ba 100644 --- a/cmd/lotus-miner/init_restore.go +++ b/cmd/lotus-miner/init_restore.go @@ -97,7 +97,7 @@ 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.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + return lcli.IncorrectNumArgs(cctx) } log.Info("Trying to connect to full node RPC") diff --git a/cmd/lotus-miner/market.go b/cmd/lotus-miner/market.go index 78b68214e..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.NArg() < 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)) @@ -618,7 +618,7 @@ var setSealDurationCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.Errorf("must pass duration in minutes") + 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 1774a8e00..6f6fd6635 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -315,7 +315,7 @@ var provingDeadlineInfoCmd = &cli.Command{ Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("must pass deadline index") + return lcli.IncorrectNumArgs(cctx) } dlIdx, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -462,7 +462,7 @@ var provingCheckProvableCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("must pass deadline index") + return lcli.IncorrectNumArgs(cctx) } dlIdx, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -617,7 +617,7 @@ It will not send any messages to the chain.`, ArgsUsage: "[deadline index]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("must pass deadline index") + return lcli.IncorrectNumArgs(cctx) } dlIdx, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -662,7 +662,7 @@ var provingRecoverFaultsCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() < 1 { - return xerrors.Errorf("must pass at least 1 sector number") + return lcli.ShowHelp(cctx, xerrors.Errorf("must pass at least 1 sector number")) } arglist := cctx.Args().Slice() diff --git a/cmd/lotus-miner/sealing.go b/cmd/lotus-miner/sealing.go index adf3b9c2f..34c84772d 100644 --- a/cmd/lotus-miner/sealing.go +++ b/cmd/lotus-miner/sealing.go @@ -373,7 +373,7 @@ var sealingAbortCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + return lcli.IncorrectNumArgs(cctx) } minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) @@ -431,7 +431,7 @@ var sealingDataCidCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() < 1 || cctx.NArg() > 2 { - return xerrors.Errorf("expected 1 or 2 arguments") + return lcli.ShowHelp(cctx, xerrors.Errorf("expected 1 or 2 arguments")) } minerApi, closer, err := lcli.GetStorageMinerAPI(cctx) diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index c6adc85b5..bcd60acf2 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -1379,7 +1379,7 @@ var sectorsTerminateCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.Errorf("must pass sector number") + return lcli.IncorrectNumArgs(cctx) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1489,7 +1489,7 @@ var sectorsRemoveCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.Errorf("must pass sector number") + return lcli.IncorrectNumArgs(cctx) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1507,7 +1507,7 @@ var sectorsSnapUpCmd = &cli.Command{ ArgsUsage: "", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number")) + return lcli.IncorrectNumArgs(cctx) } minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx) @@ -1588,7 +1588,7 @@ var sectorsStartSealCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.Errorf("must pass sector number") + return lcli.IncorrectNumArgs(cctx) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1612,7 +1612,7 @@ var sectorsSealDelayCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.Errorf("must pass duration in minutes") + return lcli.IncorrectNumArgs(cctx) } hs, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -1715,7 +1715,7 @@ var sectorsUpdateCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) if cctx.NArg() < 2 { - return xerrors.Errorf("must pass sector number and new state") + return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number and new state")) } id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) @@ -2311,7 +2311,7 @@ var sectorsNumbersReserveCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() != 2 { - return xerrors.Errorf("expected 2 arguments: [reservation name] [reserved ranges]") + return lcli.IncorrectNumArgs(cctx) } bf, err := strle.HumanRangesToBitField(cctx.Args().Get(1)) @@ -2336,7 +2336,7 @@ var sectorsNumbersFreeCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument: [reservation name]") + return lcli.IncorrectNumArgs(cctx) } return minerAPI.SectorNumFree(ctx, cctx.Args().First()) diff --git a/cmd/lotus-shed/actor.go b/cmd/lotus-shed/actor.go index d91c6de93..9d1fd9d19 100644 --- a/cmd/lotus-shed/actor.go +++ b/cmd/lotus-shed/actor.go @@ -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 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/datastore.go b/cmd/lotus-shed/datastore.go index cd650d122..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" ) @@ -172,7 +173,7 @@ var datastoreBackupStatCmd = &cli.Command{ ArgsUsage: "[file]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + return lcli.IncorrectNumArgs(cctx) } f, err := os.Open(cctx.Args().First()) @@ -221,7 +222,7 @@ var datastoreBackupListCmd = &cli.Command{ ArgsUsage: "[file]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + 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 b33b2b4ec..214b1d5df 100644 --- a/cmd/lotus-shed/export-car.go +++ b/cmd/lotus-shed/export-car.go @@ -39,7 +39,7 @@ var exportCarCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return lcli.ShowHelp(cctx, fmt.Errorf("must specify file name and object")) + return lcli.IncorrectNumArgs(cctx) } outfile := cctx.Args().First() 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 d58c634b0..e4268a291 100644 --- a/cmd/lotus-shed/miner-multisig.go +++ b/cmd/lotus-shed/miner-multisig.go @@ -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) @@ -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) 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 9be1b7fdc..348626fe1 100644 --- a/cmd/lotus-shed/miner.go +++ b/cmd/lotus-shed/miner.go @@ -136,7 +136,7 @@ var minerCreateCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() != 4 { - return xerrors.Errorf("expected 4 args (sender owner worker sectorSize)") + return lcli.IncorrectNumArgs(cctx) } sender, err := address.NewFromString(cctx.Args().First()) @@ -274,7 +274,7 @@ var minerUnpackInfoCmd = &cli.Command{ ArgsUsage: "[allinfo.txt] [dir]", Action: func(cctx *cli.Context) error { if cctx.NArg() != 2 { - return xerrors.Errorf("expected 2 args") + return lcli.IncorrectNumArgs(cctx) } src, err := homedir.Expand(cctx.Args().Get(0)) @@ -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()) diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 34b260961..847b93d9f 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -28,7 +28,7 @@ var msgCmd = &cli.Command{ ArgsUsage: "Message in any form", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("expected 1 argument") + 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 752469778..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{ @@ -43,7 +45,7 @@ var verifySealProofCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return fmt.Errorf("must specify commR, commD, and proof to verify") + 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 82412e317..3be269358 100644 --- a/cmd/lotus-shed/rpc.go +++ b/cmd/lotus-shed/rpc.go @@ -113,7 +113,7 @@ var rpcCmd = &cli.Command{ if cctx.Args().Present() { if cctx.NArg() > 2 { - return xerrors.Errorf("expected 1 or 2 arguments: method [params]") + 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 891110859..52d07f5b6 100644 --- a/cmd/lotus-shed/sectors.go +++ b/cmd/lotus-shed/sectors.go @@ -65,7 +65,7 @@ var terminateSectorCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() < 1 { - return fmt.Errorf("at least one sector must be specified") + return lcli.ShowHelp(cctx, fmt.Errorf("at least one sector must be specified")) } var maddr address.Address @@ -201,7 +201,7 @@ var terminateSectorPenaltyEstimationCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if cctx.NArg() < 1 { - return fmt.Errorf("at least one sector must be specified") + return lcli.ShowHelp(cctx, fmt.Errorf("at least one sector must be specified")) } var maddr address.Address 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 d06ae56ea..536f8e82d 100644 --- a/cmd/lotus-shed/signatures.go +++ b/cmd/lotus-shed/signatures.go @@ -32,7 +32,7 @@ var sigsVerifyBlsMsgsCmd = &cli.Command{ Usage: "", Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { - return xerrors.Errorf("usage: ") + return lcli.IncorrectNumArgs(cctx) } api, closer, err := lcli.GetFullNodeAPI(cctx) @@ -102,7 +102,7 @@ var sigsVerifyVoteCmd = &cli.Command{ Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return xerrors.Errorf("usage: verify-vote ") + return lcli.IncorrectNumArgs(cctx) } fip, err := strconv.ParseInt(cctx.Args().First(), 10, 64) diff --git a/cmd/lotus-shed/sync.go b/cmd/lotus-shed/sync.go index 915ef38d0..eb11dea27 100644 --- a/cmd/lotus-shed/sync.go +++ b/cmd/lotus-shed/sync.go @@ -39,9 +39,7 @@ var syncValidateCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() < 1 { - fmt.Println("usage: ...") - fmt.Println("At least one block cid must be provided") - return nil + return lcli.ShowHelp(cctx, fmt.Errorf("at least one block cid must be provided")) } args := cctx.Args().Slice() @@ -91,9 +89,7 @@ var syncScrapePowerCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) if cctx.NArg() < 1 { - fmt.Println("usage: ...") - fmt.Println("At least one block cid must be provided") - return nil + 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 c04dfa94c..0fa905b5f 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -47,7 +47,7 @@ var verifRegAddVerifierFromMsigCmd = &cli.Command{ ArgsUsage: " ", Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return fmt.Errorf("must specify three arguments: sender, verifier, and allowance") + return lcli.IncorrectNumArgs(cctx) } sender, err := address.NewFromString(cctx.Args().Get(0)) @@ -120,7 +120,7 @@ var verifRegAddVerifierFromAccountCmd = &cli.Command{ ArgsUsage: " ", Action: func(cctx *cli.Context) error { if cctx.NArg() != 3 { - return fmt.Errorf("must specify three arguments: sender, verifier, and allowance") + return lcli.IncorrectNumArgs(cctx) } sender, err := address.NewFromString(cctx.Args().Get(0)) @@ -202,7 +202,7 @@ var verifRegVerifyClientCmd = &cli.Command{ } if cctx.NArg() != 2 { - return fmt.Errorf("must specify two arguments: address and allowance") + return lcli.IncorrectNumArgs(cctx) } target, err := address.NewFromString(cctx.Args().Get(0)) @@ -419,7 +419,7 @@ var verifRegRemoveVerifiedClientDataCapCmd = &cli.Command{ ArgsUsage: " ", Action: func(cctx *cli.Context) error { if cctx.NArg() != 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") + return lcli.IncorrectNumArgs(cctx) } srv, err := lcli.GetFullNodeServices(cctx)