Add helper function to print usage when wrong number of arguments are supplied
This commit is contained in:
+1
-1
@@ -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") {
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+4
-4
@@ -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 <inputPath>")
|
||||
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 <inputPath> <outputPath>")
|
||||
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]
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
@@ -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") != "" {
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+13
-13
@@ -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)
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+11
-11
@@ -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: <from> <to> <available funds>"))
|
||||
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: <from address> <to address>"))
|
||||
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: <channel address>"))
|
||||
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: <channel> <amount>"))
|
||||
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))
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+3
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user