2019-06-25 11:42:17 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2019-12-09 12:36:56 +00:00
|
|
|
"strings"
|
2019-07-09 12:08:43 +00:00
|
|
|
|
2020-01-08 19:10:57 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-05-20 17:43:22 +00:00
|
|
|
|
2019-10-18 04:47:41 +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-06-25 11:42:17 +00:00
|
|
|
)
|
|
|
|
|
2019-07-23 18:49:09 +00:00
|
|
|
var log = logging.Logger("cli")
|
|
|
|
|
2020-02-25 23:17:15 +00:00
|
|
|
// custom CLI error
|
|
|
|
|
|
|
|
type ErrCmdFailed struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ErrCmdFailed) Error() string {
|
|
|
|
return e.msg
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCliError(s string) error {
|
|
|
|
return &ErrCmdFailed{s}
|
|
|
|
}
|
|
|
|
|
2019-07-09 12:08:43 +00:00
|
|
|
// 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
|
|
|
|
2021-02-23 14:50:47 +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
|
|
|
|
}
|
|
|
|
|
2021-03-05 20:08:14 +00:00
|
|
|
var GetAPIInfo = cliutil.GetAPIInfo
|
|
|
|
var GetRawAPI = cliutil.GetRawAPI
|
|
|
|
var GetAPI = cliutil.GetAPI
|
2020-08-30 18:28:58 +00:00
|
|
|
|
2021-03-05 20:08:14 +00:00
|
|
|
var DaemonContext = cliutil.DaemonContext
|
|
|
|
var ReqContext = cliutil.ReqContext
|
2020-08-30 18:28:58 +00:00
|
|
|
|
2021-03-05 20:08:14 +00:00
|
|
|
var GetFullNodeAPI = cliutil.GetFullNodeAPI
|
|
|
|
var GetGatewayAPI = cliutil.GetGatewayAPI
|
2019-09-17 18:36:06 +00:00
|
|
|
|
2021-03-05 20:08:14 +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,
|
2020-04-27 22:26:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-06-25 11:42:17 +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
|
2019-06-28 09:03:28 +00:00
|
|
|
}
|