cli

package
v0.0.57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupConsole added in v0.0.56

func SetupConsole(ctx context.Context, factory ConsoleFactory) error

SetupConsole 从上下文取控制台接口

Types

type AsyncClient added in v0.0.57

type AsyncClient interface {
	GetContext() context.Context
	GetFactory() ClientFactory

	Execute(cmd string) task.Promise
	ExecuteTask(task *Task) task.Promise
	ExecuteScript(script string) task.Promise
	ExecuteWithArguments(cmd string, args []string) task.Promise
}

AsyncClient 是用于执行命令的异步 API

type Client

type Client interface {
	GetContext() context.Context
	GetFactory() ClientFactory

	Execute(cmd string) error
	ExecuteTask(task *Task) error
	ExecuteWithArguments(cmd string, args []string) error

	// execute multi-line commands
	ExecuteScript(script string) error
}

Client 是用于执行命令的同步 API

type ClientFactory added in v0.0.57

type ClientFactory interface {
	CreateClient(ctx context.Context) Client
	CreateAsyncClient(ctx context.Context) AsyncClient
}

ClientFactory 是命令客户端的工厂

type CommandHelpInfo added in v0.0.56

type CommandHelpInfo struct {
	Name        string
	Title       string
	Description string
	Content     string
}

CommandHelpInfo 是命令的帮助信息

type CommandHelper added in v0.0.56

type CommandHelper interface {
	GetHelpInfo() *CommandHelpInfo
}

CommandHelper 是命令的帮助信息提供者, 通常与Handler 实现于同一个结构

type Console added in v0.0.56

type Console interface {
	GetWD() string
	SetWD(wd string)

	GetWorkingPath() fs.Path
	SetWorkingPath(wd fs.Path)

	Error() io.Writer
	Output() io.Writer
	Input() io.Reader

	SetError(w io.Writer)
	SetOutput(w io.Writer)
	SetInput(r io.Reader)
}

Console 接口表示一个跟上下文绑定的控制台

func GetConsole added in v0.0.56

func GetConsole(ctx context.Context) (Console, error)

GetConsole 从上下文取控制台接口

type ConsoleFactory added in v0.0.56

type ConsoleFactory interface {
	Create() Console
}

ConsoleFactory 是创建 Console 的工厂

type Context added in v0.0.57

type Context struct {
	markup.Component `id:"cli-context"`

	Service       Service       `inject:"#cli-service"`
	ClientFactory ClientFactory `inject:"#cli-client-factory"`
	Filters       []Filter      `inject:".cli-filter"`
	Handlers      []Handler     `inject:".cli-handler"`
}

type Filter added in v0.0.56

type Filter interface {
	Init(service Service) error
	Handle(ctx *TaskContext, next FilterChain) error
}

Filter 用来过滤请求

type FilterChain added in v0.0.56

type FilterChain interface {
	Handle(ctx *TaskContext) error
}

FilterChain 代表过滤器链条

type FilterChainBuilder added in v0.0.56

type FilterChainBuilder struct {
	// contains filtered or unexported fields
}

func (*FilterChainBuilder) Add added in v0.0.56

func (inst *FilterChainBuilder) Add(priority int, filter Filter)

func (*FilterChainBuilder) Create added in v0.0.56

func (inst *FilterChainBuilder) Create(reverse bool) FilterChain

func (*FilterChainBuilder) Len added in v0.0.56

func (inst *FilterChainBuilder) Len() int

func (*FilterChainBuilder) Less added in v0.0.56

func (inst *FilterChainBuilder) Less(a, b int) bool

func (*FilterChainBuilder) Swap added in v0.0.56

func (inst *FilterChainBuilder) Swap(a, b int)

type Handler

type Handler interface {
	Init(service Service) error
	Handle(ctx *TaskContext) error
}

Handler 是某条具体命令的处理器

type Service

type Service interface {
	RegisterHandler(name string, h Handler) error

	FindHandler(name string) (Handler, error)

	GetHandlerNames() []string

	// AddFilter 添加一个过滤器到服务中。
	// priority 是过滤器的优先顺序,数值越大,优先级越高,处理顺序越靠前。
	AddFilter(priority int, filter Filter) error

	GetFilterChain() FilterChain

	GetClient(ctx context.Context) Client

	GetClientFactory() ClientFactory
}

Service 是用来处理命令的服务

type Task

type Task struct {
	Context  context.Context
	TaskList []*TaskUnit
	Script   string
}

Task 表示将要执行的任务

type TaskContext added in v0.0.56

type TaskContext struct {
	Context     context.Context
	CurrentTask *TaskUnit
	Handler     Handler
	Service     Service
	TaskList    []*TaskUnit
}

TaskContext 表示正在执行的任务

func (*TaskContext) Clone added in v0.0.56

func (inst *TaskContext) Clone() *TaskContext

Clone 生成 TaskContext 的副本(浅拷贝)

type TaskListBuilder added in v0.0.57

type TaskListBuilder struct {
	// contains filtered or unexported fields
}

func (*TaskListBuilder) AddLine added in v0.0.57

func (inst *TaskListBuilder) AddLine(line string, index int, args []string) error

func (*TaskListBuilder) Create added in v0.0.57

func (inst *TaskListBuilder) Create() []*TaskUnit

func (*TaskListBuilder) ParseScript added in v0.0.57

func (inst *TaskListBuilder) ParseScript(script string) error

type TaskUnit added in v0.0.56

type TaskUnit struct {
	LineNumber  int
	CommandName string
	CommandLine string
	Arguments   []string
}

TaskUnit 表示一条简单的命令

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL