72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"strings"
|
|
|
|
logging "github.com/ipfs/go-log/v2"
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
|
)
|
|
|
|
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
|
|
type ApiConnector func() api.FullNode
|
|
|
|
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
|
|
|
|
var DaemonContext = cliutil.DaemonContext
|
|
var ReqContext = cliutil.ReqContext
|
|
|
|
var GetFullNodeAPI = cliutil.GetFullNodeAPI
|
|
var GetFullNodeAPIV1 = cliutil.GetFullNodeAPIV1
|
|
var GetGatewayAPI = cliutil.GetGatewayAPI
|
|
|
|
var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
|
|
var GetWorkerAPI = cliutil.GetWorkerAPI
|
|
|
|
var CommonCommands = []*cli.Command{
|
|
AuthCmd,
|
|
LogCmd,
|
|
WaitApiCmd,
|
|
FetchParamCmd,
|
|
PprofCmd,
|
|
VersionCmd,
|
|
}
|
|
|
|
func WithCategory(cat string, cmd *cli.Command) *cli.Command {
|
|
cmd.Category = strings.ToUpper(cat)
|
|
return cmd
|
|
}
|