lotus/cli/cmd.go

94 lines
2.0 KiB
Go
Raw Permalink Normal View History

package cli
import (
"strings"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
2020-05-20 17:43:22 +00:00
"github.com/filecoin-project/lotus/api"
2020-10-09 00:57:41 +00:00
cliutil "github.com/filecoin-project/lotus/cli/util"
)
2019-07-23 18:49:09 +00:00
var log = logging.Logger("cli")
// custom CLI error
type ErrCmdFailed struct {
msg string
}
func (e *ErrCmdFailed) Error() string {
return e.msg
}
func NewCliError(s string) error {
return &ErrCmdFailed{s}
}
// ApiConnector returns API instance
2019-07-24 00:09:34 +00:00
type ApiConnector func() api.FullNode
2019-07-08 19:07:16 +00:00
func GetFullNodeServices(ctx *cli.Context) (ServicesAPI, error) {
if tn, ok := ctx.App.Metadata["test-services"]; ok {
return tn.(ServicesAPI), nil
}
api, c, err := GetFullNodeAPIV1(ctx)
if err != nil {
return nil, err
}
return &ServicesImpl{api: api, closer: c}, nil
}
var GetAPIInfo = cliutil.GetAPIInfo
var GetRawAPI = cliutil.GetRawAPI
var GetAPI = cliutil.GetCommonAPI
2020-08-30 18:28:58 +00:00
var DaemonContext = cliutil.DaemonContext
var ReqContext = cliutil.ReqContext
2020-08-30 18:28:58 +00:00
var GetFullNodeAPI = cliutil.GetFullNodeAPI
2021-04-05 11:47:10 +00:00
var GetFullNodeAPIV1 = cliutil.GetFullNodeAPIV1
var GetGatewayAPI = cliutil.GetGatewayAPI
2019-09-17 18:36:06 +00:00
var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
var GetMarketsAPI = cliutil.GetMarketsAPI
var GetWorkerAPI = cliutil.GetWorkerAPI
2019-07-08 19:07:16 +00:00
2020-03-23 12:29:24 +00:00
var CommonCommands = []*cli.Command{
2021-03-23 23:25:49 +00:00
AuthCmd,
2021-03-23 23:19:22 +00:00
LogCmd,
2021-03-23 23:26:12 +00:00
WaitApiCmd,
2021-03-23 23:27:34 +00:00
FetchParamCmd,
2021-03-23 23:26:59 +00:00
PprofCmd,
2020-08-04 18:57:40 +00:00
VersionCmd,
2020-03-23 12:29:24 +00:00
}
var Commands = []*cli.Command{
2020-07-21 17:19:47 +00:00
WithCategory("basic", sendCmd),
WithCategory("basic", walletCmd),
WithCategory("basic", clientCmd),
WithCategory("basic", multisigCmd),
2021-04-28 23:24:09 +00:00
WithCategory("basic", filplusCmd),
2020-07-21 17:19:47 +00:00
WithCategory("basic", paychCmd),
2021-03-23 23:25:49 +00:00
WithCategory("developer", AuthCmd),
2021-03-23 23:28:27 +00:00
WithCategory("developer", MpoolCmd),
2021-03-23 23:21:04 +00:00
WithCategory("developer", StateCmd),
2021-03-23 23:19:33 +00:00
WithCategory("developer", ChainCmd),
2021-03-23 23:19:22 +00:00
WithCategory("developer", LogCmd),
2021-03-23 23:26:12 +00:00
WithCategory("developer", WaitApiCmd),
2021-03-23 23:27:34 +00:00
WithCategory("developer", FetchParamCmd),
2021-03-23 23:15:02 +00:00
WithCategory("network", NetCmd),
2021-03-23 23:23:22 +00:00
WithCategory("network", SyncCmd),
WithCategory("status", StatusCmd),
2021-03-23 23:26:59 +00:00
PprofCmd,
2020-08-04 18:57:40 +00:00
VersionCmd,
2020-05-13 11:08:59 +00:00
}
2020-07-21 17:19:47 +00:00
func WithCategory(cat string, cmd *cli.Command) *cli.Command {
2021-02-10 13:38:42 +00:00
cmd.Category = strings.ToUpper(cat)
2020-05-13 11:08:59 +00:00
return cmd
}