sprinkle some nice helptext returns around

This commit is contained in:
whyrusleeping 2020-07-23 12:31:28 -07:00
parent d547bd9f83
commit fcef3696bc
4 changed files with 54 additions and 66 deletions

View File

@ -68,6 +68,10 @@ 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"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -75,10 +79,6 @@ var msigCreateCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() < 1 {
return fmt.Errorf("multisigs must have at least one signer")
}
var addrs []address.Address
for _, a := range cctx.Args().Slice() {
addr, err := address.NewFromString(a)
@ -159,6 +159,10 @@ var msigInspectCmd = &cli.Command{
ArgsUsage: "[address]",
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return ShowHelp(cctx, fmt.Errorf("must specify address of multisig to inspect"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -166,10 +170,6 @@ var msigInspectCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify address of multisig to inspect")
}
maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
@ -287,6 +287,14 @@ var msigProposeCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() < 3 {
return ShowHelp(cctx, fmt.Errorf("must pass at least multisig address, destination, and value"))
}
if cctx.Args().Len() > 3 && cctx.Args().Len() != 5 {
return ShowHelp(cctx, fmt.Errorf("must either pass three or five arguments"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -294,14 +302,6 @@ var msigProposeCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() < 3 {
return fmt.Errorf("must pass multisig address, destination, and value")
}
if cctx.Args().Len() > 3 && cctx.Args().Len() != 5 {
return fmt.Errorf("usage: msig propose <msig addr> <desination> <value> [ <method> <params> ]")
}
msig, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
@ -391,6 +391,14 @@ var msigApproveCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() < 5 {
return ShowHelp(cctx, fmt.Errorf("must pass multisig address, message ID, proposer address, destination, and value"))
}
if cctx.Args().Len() > 5 && cctx.Args().Len() != 7 {
return ShowHelp(cctx, fmt.Errorf("usage: msig approve <msig addr> <message ID> <proposer address> <desination> <value> [ <method> <params> ]"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -398,14 +406,6 @@ var msigApproveCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() < 5 {
return fmt.Errorf("must pass multisig address, message ID, proposer address, destination, and value")
}
if cctx.Args().Len() > 5 && cctx.Args().Len() != 7 {
return fmt.Errorf("usage: msig approve <msig addr> <message ID> <proposer address> <desination> <value> [ <method> <params> ]")
}
msig, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
@ -500,6 +500,10 @@ 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"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -507,10 +511,6 @@ var msigSwapProposeCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() != 3 {
return fmt.Errorf("must pass multisig address, old signer address, new signer address")
}
msig, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
@ -572,6 +572,10 @@ 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"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -579,10 +583,6 @@ var msigSwapApproveCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() != 5 {
return fmt.Errorf("must pass multisig address, proposer address, transaction id, old signer address, new signer address")
}
msig, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
@ -654,6 +654,10 @@ 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"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -661,10 +665,6 @@ var msigSwapCancelCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
if cctx.Args().Len() != 4 {
return fmt.Errorf("must pass multisig address, transaction id, old signer address, new signer address")
}
msig, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base64"
"fmt"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/go-address"
@ -29,22 +30,22 @@ var paychGetCmd = &cli.Command{
ArgsUsage: "[fromAddress toAddress amount]",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 3 {
return fmt.Errorf("must pass three arguments: <from> <to> <available funds>")
return ShowHelp(cctx, fmt.Errorf("must pass three arguments: <from> <to> <available funds>"))
}
from, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return fmt.Errorf("failed to parse from address: %s", err)
return ShowHelp(cctx, fmt.Errorf("failed to parse from address: %s", err))
}
to, err := address.NewFromString(cctx.Args().Get(1))
if err != nil {
return fmt.Errorf("failed to parse to address: %s", err)
return ShowHelp(cctx, fmt.Errorf("failed to parse to address: %s", err))
}
amt, err := types.BigFromString(cctx.Args().Get(2))
if err != nil {
return fmt.Errorf("parsing amount failed: %s", err)
return ShowHelp(cctx, fmt.Errorf("parsing amount failed: %s", err))
}
api, closer, err := GetFullNodeAPI(cctx)
@ -115,7 +116,7 @@ var paychVoucherCreateCmd = &cli.Command{
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 2 {
return fmt.Errorf("must pass two arguments: <channel> <amount>")
return ShowHelp(cctx, fmt.Errorf("must pass two arguments: <channel> <amount>"))
}
ch, err := address.NewFromString(cctx.Args().Get(0))
@ -159,7 +160,7 @@ var paychVoucherCheckCmd = &cli.Command{
ArgsUsage: "[channelAddress voucher]",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 2 {
return fmt.Errorf("must pass payment channel address and voucher to validate")
return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher to validate"))
}
ch, err := address.NewFromString(cctx.Args().Get(0))
@ -195,7 +196,7 @@ var paychVoucherAddCmd = &cli.Command{
ArgsUsage: "[channelAddress voucher]",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 2 {
return fmt.Errorf("must pass payment channel address and voucher")
return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher"))
}
ch, err := address.NewFromString(cctx.Args().Get(0))
@ -237,7 +238,7 @@ var paychVoucherListCmd = &cli.Command{
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 1 {
return fmt.Errorf("must pass payment channel address")
return ShowHelp(cctx, fmt.Errorf("must pass payment channel address"))
}
ch, err := address.NewFromString(cctx.Args().Get(0))
@ -281,7 +282,7 @@ var paychVoucherBestSpendableCmd = &cli.Command{
ArgsUsage: "[channelAddress]",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 1 {
return fmt.Errorf("must pass payment channel address")
return ShowHelp(cctx, fmt.Errorf("must pass payment channel address"))
}
ch, err := address.NewFromString(cctx.Args().Get(0))
@ -336,7 +337,7 @@ var paychVoucherSubmitCmd = &cli.Command{
ArgsUsage: "[channelAddress voucher]",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 2 {
return fmt.Errorf("must pass payment channel address and voucher")
return ShowHelp(cctx, fmt.Errorf("must pass payment channel address and voucher"))
}
ch, err := address.NewFromString(cctx.Args().Get(0))

View File

@ -29,6 +29,10 @@ var sendCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 2 {
return ShowHelp(cctx, fmt.Errorf("'send' expects two arguments, target and amount"))
}
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
@ -37,18 +41,14 @@ var sendCmd = &cli.Command{
ctx := ReqContext(cctx)
if cctx.Args().Len() != 2 {
return fmt.Errorf("'send' expects two arguments, target and amount")
}
toAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
return ShowHelp(cctx, fmt.Errorf("failed to parse target address: %w", err))
}
val, err := types.ParseFIL(cctx.Args().Get(1))
if err != nil {
return err
return ShowHelp(cctx, fmt.Errorf("failed to parse amount: %w", err))
}
var fromAddr address.Address

View File

@ -2,7 +2,6 @@ package main
import (
"context"
"os"
"github.com/urfave/cli/v2"
"go.opencensus.io/trace"
@ -69,17 +68,5 @@ func main() {
app.Metadata["traceContext"] = ctx
app.Metadata["repoType"] = repo.FullNode
if err := app.Run(os.Args); err != nil {
span.SetStatus(trace.Status{
Code: trace.StatusCodeFailedPrecondition,
Message: err.Error(),
})
_, ok := err.(*lcli.ErrCmdFailed)
if ok {
log.Debugf("%+v", err)
} else {
log.Warnf("%+v", err)
}
os.Exit(1)
}
lcli.RunApp(app)
}