Merge pull request #2555 from filecoin-project/feat/helptext-helpers
sprinkle some nice helptext returns around
This commit is contained in:
commit
69cb7f6b03
@ -67,6 +67,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
|
||||
@ -74,10 +78,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)
|
||||
@ -158,6 +158,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
|
||||
@ -165,10 +169,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
|
||||
@ -282,6 +282,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
|
||||
@ -289,14 +297,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
|
||||
@ -386,6 +386,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
|
||||
@ -393,14 +401,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
|
||||
@ -495,6 +495,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
|
||||
@ -502,10 +506,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
|
||||
@ -567,6 +567,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
|
||||
@ -574,10 +578,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
|
||||
@ -649,6 +649,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
|
||||
@ -656,10 +660,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
|
||||
|
21
cli/paych.go
21
cli/paych.go
@ -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))
|
||||
|
12
cli/send.go
12
cli/send.go
@ -51,6 +51,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
|
||||
@ -59,18 +63,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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user