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
|
|
|
|
}
|
|
|
|
|
2021-03-24 14:12:35 +00:00
|
|
|
api, c, err := GetFullNodeAPIV1(ctx)
|
2021-02-23 14:50:47 +00:00
|
|
|
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
|
2021-07-29 11:37:29 +00:00
|
|
|
var GetAPI = cliutil.GetCommonAPI
|
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
|
2021-04-05 11:47:10 +00:00
|
|
|
var GetFullNodeAPIV1 = cliutil.GetFullNodeAPIV1
|
2021-03-05 20:08:14 +00:00
|
|
|
var GetGatewayAPI = cliutil.GetGatewayAPI
|
2019-09-17 18:36:06 +00:00
|
|
|
|
2021-03-05 20:08:14 +00:00
|
|
|
var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
|
2021-07-29 11:37:29 +00:00
|
|
|
var GetMarketsAPI = cliutil.GetMarketsAPI
|
2021-03-05 20:08:14 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|