Merge pull request #10114 from filecoin-project/fix/cli-cleanup

chore: cli: cleanup cli
This commit is contained in:
Geoff Stuart 2023-01-26 09:25:40 -05:00 committed by GitHub
commit c45df789ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 74 deletions

View File

@ -112,8 +112,8 @@ var ChainGetBlock = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass cid of block to print")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
bcid, err := cid.Decode(cctx.Args().First())
@ -198,6 +198,10 @@ var ChainReadObjCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
c, err := cid.Decode(cctx.Args().First())
if err != nil {
return fmt.Errorf("failed to parse cid input: %s", err)
@ -233,6 +237,10 @@ var ChainDeleteObjCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
c, err := cid.Decode(cctx.Args().First())
if err != nil {
return fmt.Errorf("failed to parse cid input: %s", err)
@ -276,6 +284,10 @@ var ChainStatObjCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
obj, err := cid.Decode(cctx.Args().First())
if err != nil {
return fmt.Errorf("failed to parse cid input: %s", err)
@ -308,8 +320,8 @@ var ChainGetMsgCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
afmt := NewAppFmt(cctx.App)
if !cctx.Args().Present() {
return fmt.Errorf("must pass a cid of a message to get")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
@ -374,6 +386,10 @@ var ChainSetHeadCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
var ts *types.TipSet
if cctx.Bool("genesis") {
@ -734,6 +750,10 @@ var ChainGetCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
p := path.Clean(cctx.Args().First())
if strings.HasPrefix(p, "/pstate") {
p = p[len("/pstate"):]
@ -1071,8 +1091,8 @@ var ChainExportCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify filename to export chain to")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
rsrs := abi.ChainEpoch(cctx.Int64("recent-stateroots"))

View File

@ -166,8 +166,8 @@ var clientDropCmd = &cli.Command{
Usage: "Remove import",
ArgsUsage: "[import ID...]",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return xerrors.Errorf("no imports specified")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
@ -996,9 +996,8 @@ var clientFindCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
fmt.Println("Usage: find [CID]")
return nil
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
file, err := cid.Parse(cctx.Args().First())
@ -1063,8 +1062,7 @@ var clientQueryRetrievalAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
afmt := NewAppFmt(cctx.App)
if cctx.NArg() != 2 {
afmt.Println("Usage: retrieval-ask [minerAddress] [data CID]")
return nil
return IncorrectNumArgs(cctx)
}
maddr, err := address.NewFromString(cctx.Args().First())
@ -1639,8 +1637,7 @@ var clientQueryAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
afmt := NewAppFmt(cctx.App)
if cctx.NArg() != 1 {
afmt.Println("Usage: query-ask [minerAddress]")
return nil
return IncorrectNumArgs(cctx)
}
maddr, err := address.NewFromString(cctx.Args().First())
@ -1944,8 +1941,8 @@ var clientGetDealCmd = &cli.Command{
Usage: "Print detailed deal information",
ArgsUsage: "[proposalCID]",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
@ -2058,8 +2055,8 @@ var clientStat = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() || cctx.NArg() != 1 {
return fmt.Errorf("must specify cid of data")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
dataCid, err := cid.Parse(cctx.Args().First())
@ -2080,8 +2077,9 @@ var clientStat = &cli.Command{
}
var clientRestartTransfer = &cli.Command{
Name: "restart-transfer",
Usage: "Force restart a stalled data transfer",
Name: "restart-transfer",
Usage: "Force restart a stalled data transfer",
ArgsUsage: "[transferID]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "peerid",
@ -2094,8 +2092,8 @@ var clientRestartTransfer = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
@ -2140,8 +2138,9 @@ var clientRestartTransfer = &cli.Command{
}
var clientCancelTransfer = &cli.Command{
Name: "cancel-transfer",
Usage: "Force cancel a data transfer",
Name: "cancel-transfer",
Usage: "Force cancel a data transfer",
ArgsUsage: "[transferID]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "peerid",
@ -2159,8 +2158,8 @@ var clientCancelTransfer = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {

View File

@ -58,8 +58,7 @@ var disputerMsgCmd = &cli.Command{
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
if cctx.NArg() != 3 {
fmt.Println("Usage: dispute [minerAddress index postIndex]")
return nil
return IncorrectNumArgs(cctx)
}
ctx := ReqContext(cctx)

View File

@ -15,8 +15,8 @@ var FetchParamCmd = &cli.Command{
Usage: "Fetch proving parameters",
ArgsUsage: "[sectorSize]",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return xerrors.Errorf("must pass sector size to fetch params for (specify as \"32GiB\", for instance)")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
sectorSizeInt, err := units.RAMInBytes(cctx.Args().First())
if err != nil {

View File

@ -99,8 +99,8 @@ var StateMinerProvingDeadlineCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify miner to get information for")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -142,8 +142,8 @@ var StateMinerInfo = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify miner to get information for")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -397,8 +397,8 @@ var StateSectorsCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify miner to list sectors for")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
maddr, err := address.NewFromString(cctx.Args().First())
@ -437,8 +437,8 @@ var StateActiveSectorsCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify miner to list sectors for")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
maddr, err := address.NewFromString(cctx.Args().First())
@ -469,8 +469,8 @@ var StateExecTraceCmd = &cli.Command{
Usage: "Get the execution trace of a given message",
ArgsUsage: "<messageCid>",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return ShowHelp(cctx, fmt.Errorf("must pass message cid"))
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
mcid, err := cid.Decode(cctx.Args().First())
@ -612,8 +612,8 @@ var StateGetDealSetCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify deal ID")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
dealid, err := strconv.ParseUint(cctx.Args().First(), 10, 64)
@ -756,8 +756,8 @@ var StateGetActorCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass address of actor to get")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -810,8 +810,8 @@ var StateLookupIDCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass address of actor to get")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -854,8 +854,8 @@ var StateSectorSizeCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass miner's address")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -891,8 +891,8 @@ var StateReadStateCmd = &cli.Command{
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass address of actor to get")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -1473,8 +1473,8 @@ var StateWaitMsgCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return fmt.Errorf("must specify message cid to wait for")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
@ -1510,8 +1510,8 @@ var StateSearchMsgCmd = &cli.Command{
Usage: "Search to see whether a message has appeared on chain",
ArgsUsage: "[messageCid]",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return fmt.Errorf("must specify message cid to search for")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)
@ -1842,11 +1842,12 @@ var StateMarketCmd = &cli.Command{
}
var stateMarketBalanceCmd = &cli.Command{
Name: "balance",
Usage: "Get the market balance (locked and escrowed) for a given account",
Name: "balance",
Usage: "Get the market balance (locked and escrowed) for a given account",
ArgsUsage: "[address]",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return ShowHelp(cctx, fmt.Errorf("must specify address to print market balance for"))
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
api, closer, err := GetFullNodeAPI(cctx)

View File

@ -251,8 +251,8 @@ var walletSetDefault = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must pass address to set as default")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -279,8 +279,8 @@ var walletExport = &cli.Command{
afmt := NewAppFmt(cctx.App)
if !cctx.Args().Present() {
return fmt.Errorf("must specify key to export")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -414,8 +414,8 @@ var walletSign = &cli.Command{
afmt := NewAppFmt(cctx.App)
if !cctx.Args().Present() || cctx.NArg() != 2 {
return fmt.Errorf("must specify signing address and message to sign")
if cctx.NArg() != 2 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -457,8 +457,8 @@ var walletVerify = &cli.Command{
afmt := NewAppFmt(cctx.App)
if !cctx.Args().Present() || cctx.NArg() != 3 {
return fmt.Errorf("must specify signing address, message, and signature to verify")
if cctx.NArg() != 3 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -509,8 +509,8 @@ var walletDelete = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() || cctx.NArg() != 1 {
return fmt.Errorf("must specify address to delete")
if cctx.NArg() != 1 {
return IncorrectNumArgs(cctx)
}
addr, err := address.NewFromString(cctx.Args().First())
@ -701,8 +701,8 @@ var walletMarketAdd = &cli.Command{
afmt := NewAppFmt(cctx.App)
// Get amount param
if !cctx.Args().Present() {
return fmt.Errorf("must pass amount to add")
if cctx.NArg() < 1 {
return IncorrectNumArgs(cctx)
}
f, err := types.ParseFIL(cctx.Args().First())
if err != nil {

View File

@ -906,7 +906,7 @@ NAME:
lotus client restart-transfer - Force restart a stalled data transfer
USAGE:
lotus client restart-transfer [command options] [arguments...]
lotus client restart-transfer [command options] [transferID]
CATEGORY:
UTIL
@ -923,7 +923,7 @@ NAME:
lotus client cancel-transfer - Force cancel a data transfer
USAGE:
lotus client cancel-transfer [command options] [arguments...]
lotus client cancel-transfer [command options] [transferID]
CATEGORY:
UTIL
@ -2034,7 +2034,7 @@ NAME:
lotus state market balance - Get the market balance (locked and escrowed) for a given account
USAGE:
lotus state market balance [command options] [arguments...]
lotus state market balance [command options] [address]
OPTIONS:
--help, -h show help (default: false)