cmd

package
v0.0.0-...-04e6e7a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCmd   = newCmd()
	DefaultFlags = []cli.Flag{
		&cli.BoolFlag{
			Name:    "version",
			Aliases: []string{"v"},
			Usage:   "show version",
		},
		&cli.StringFlag{
			Name:    "region",
			Usage:   "service region",
			EnvVars: []string{"CERES_REGION"},
		},
		&cli.StringFlag{
			Name:    "zone",
			Usage:   "service zone",
			EnvVars: []string{"CERES_ZONE"},
		},
	}
)
View Source
var (
	DefaultPluginManager = &PluginManager{
		smu:     sync.RWMutex{},
		plugins: make(map[string]Plugin),
	}
)

Functions

func FrameVersion

func FrameVersion() string

FrameVersion 获取框架版本

func GetAppName

func GetAppName() string

GetAppName 获取应用名称

func GetAppVersion

func GetAppVersion() string

GetAppVersion 获取应用版本

func GetBuildHost

func GetBuildHost() string

GetBuildHost 获取构建host

func GetBuildTime

func GetBuildTime() string

GetBuildTime 获取构建时间

func GetBuildUser

func GetBuildUser() string

GetBuildUser 获取构建用户

func GetCeresVersion

func GetCeresVersion() string

GetCeresVersion 获取go-ceres版本

func GetHostname

func GetHostname() string

GetHostname 获取hostname

func GetRegion

func GetRegion() string

GetRegion 获取数据中心

func GetStartTime

func GetStartTime() string

GetStartTime 获取启动时间

func GetZone

func GetZone() string

GetZone 获取区域

func IsRegisteredPlugin

func IsRegisteredPlugin(p Plugin) bool

IsRegisteredPlugin 判断是否已经注册插件

func RangePlugins

func RangePlugins(fn func(n string, p Plugin) bool)

RangePlugins 循环插件

func RegisterPlugin

func RegisterPlugin(p Plugin) error

RegisterPlugin 注册插件

func SetAppName

func SetAppName(name string)

SetAppName 设置应用名称

func SetAppVersion

func SetAppVersion(v string)

SetAppVersion 设置应用版本

func SetBuildTime

func SetBuildTime(s string)

SetBuildTime 设置构建时间

func ShowVersion

func ShowVersion()

ShowVersion 输出版本信息

Types

type Command

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

func (*Command) App

func (c *Command) App() *cli.App

App 获取应用信息

func (Command) Before

func (c Command) Before(ctx *cli.Context) (err error)

Before 应用运行前

func (*Command) Context

func (c *Command) Context() *cli.Context

Context 获取应用

func (*Command) Init

func (c *Command) Init(opts ...Option) error

Init 初始化命令行

type Option

type Option func(o *Options)

func Name

func Name(name string) Option

Name 设置应用名称

func WithDescription

func WithDescription(desc string) Option

WithDescription 设置应用介绍

func WithFlags

func WithFlags(flags []cli.Flag) Option

WithFlags 添加命令参数

func WithUsage

func WithUsage(usa string) Option

WithUsage 设置应用后面短简介

func WithVersion

func WithVersion(v string) Option

WithVersion 设置应用介绍

type Options

type Options struct {
	Name        string
	Usage       string
	Description string
	Version     string
	Flags       []cli.Flag
}

type Plugin

type Plugin interface {
	// Name 获取插件名称
	Name() string
	// Flags 返回该插件需要注入的flags
	Flags() []cli.Flag
	// Init 初始化插件时会调用该方法
	Init(ctx *cli.Context) error
	// Config 配置组件加载完毕后调用该方法
	Config() error
	// Destroy 应用退出时调用,用于释放资源
	Destroy()
}

Plugin 插件接口定义

type PluginManager

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

PluginManager 插件管理器定义

func (*PluginManager) IsRegistered

func (m *PluginManager) IsRegistered(p Plugin) bool

IsRegistered 判断插件是否已经注册

func (*PluginManager) Range

func (m *PluginManager) Range(fn func(n string, p Plugin) bool)

Range 循环插件

func (*PluginManager) Register

func (m *PluginManager) Register(p Plugin) error

Register 注册插件

Directories

Path Synopsis
plugins

Jump to

Keyboard shortcuts

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