lotus/cli/cmd.go

91 lines
1.9 KiB
Go
Raw 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 := GetFullNodeAPI(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.GetAPI
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
var GetGatewayAPI = cliutil.GetGatewayAPI
2019-09-17 18:36:06 +00:00
var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
var GetWorkerAPI = cliutil.GetWorkerAPI
2019-07-08 19:07:16 +00:00
2020-03-23 12:29:24 +00:00
var CommonCommands = []*cli.Command{
netCmd,
2020-05-13 11:08:59 +00:00
authCmd,
2020-03-23 12:29:24 +00:00
logCmd,
waitApiCmd,
2020-05-13 11:08:59 +00:00
fetchParamCmd,
2020-08-17 09:48:12 +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),
WithCategory("basic", paychCmd),
WithCategory("developer", authCmd),
WithCategory("developer", mpoolCmd),
WithCategory("developer", stateCmd),
WithCategory("developer", chainCmd),
WithCategory("developer", logCmd),
WithCategory("developer", waitApiCmd),
WithCategory("developer", fetchParamCmd),
WithCategory("network", netCmd),
WithCategory("network", syncCmd),
2020-08-17 09:48:12 +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
}