plugin

package
v0.0.0-...-af25eba Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataFileName = "metadata.yaml"

MetadataFileName 定義了 metadata 的檔案名稱

View Source
const SourceFileName = ".source"

SourceFileName 定義了 source 的檔案名稱

Variables

View Source
var (
	// SupportedExtensions 代表所有支援壓縮檔的副檔名
	SupportedExtensions = []string{
		".zip",
		".tar",
		".tar.gz",
		".tgz",
		".tar.bz2",
		".tbz2",
		".tar.xz",
		".txz",
		".tar.lz4",
		".tlz4",
		".tar.sz",
		".tsz",
		".rar",
		".bz2",
		".gz",
		".lz4",
		".sz",
		".xz",
	}
	// GitHubRepo 代表檢查 github repo 文字的 regular expression
	GitHubRepo = regexp.MustCompile(`^(http[s]?://)?github.com/([^/]+)/([^/]+)[/]?$`)
)
View Source
var Creators = func() (m map[string]creator) {
	m = make(map[string]creator, len(registeredCreators))
	for _, c := range registeredCreators {
		m[reflect.TypeOf(c).Name()] = c
	}
	return
}()

Creators expose creators 讓 command 可以輸出給使用者參考

View Source
var (
	// Envs expose plugin envs 範例讓 command 可以輸出給使用者參考
	Envs = func() (m map[string]string) {
		plugName := "foo"
		return envsMap(
			plugName,
			filepath.Join(environment.Settings.Home.Plugins(), plugName),
			filepath.Join(environment.Settings.Home.Mounts(), plugName),
			"<version.of.slctl>",
			"<github.token>")
	}()
)

Functions

func Cleanup

func Cleanup(log *logrus.Logger, home paths.Home, force bool, dryRun bool) error

Cleanup remove outdated downloads of plugin

func Create

func Create(lang string, plugin *Metadata, path string) (string, error)

Create 產生 plugin template

func IsGitHubRepo

func IsGitHubRepo(source string) bool

IsGitHubRepo 回傳 source 是否為 GitHub Repo

func IsLocalDirReference

func IsLocalDirReference(source string) bool

IsLocalDirReference 回傳 source 是否為 local 路徑並且為一個資料夾, 如 C:\some-dir, 而不是 https://...

func IsLocalReference

func IsLocalReference(source string) bool

IsLocalReference 回傳 source 是否為 local 路徑 如 C:\some-path, 而不是 https://...

func IsSupportedArchive

func IsSupportedArchive(source string) bool

IsSupportedArchive 回傳 source 是否支援傳入的檔案路徑的副檔名

func LoadPluginCommands

func LoadPluginCommands(metadata *release.Metadata) ([]*cobra.Command, error)

LoadPluginCommands 將 plugin 載入後轉換成 command

Types

type Commands

type Commands struct {
	Command  string     `json:"command"`
	Platform []Platform `json:"platform"`
}

Commands 封裝了執行 plugin 的執行命令

func (*Commands) GetCommand

func (c *Commands) GetCommand() (command string, err error)

GetCommand 取得符合當前系統環境的執行命令

type ErrNoCommandFound

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

ErrNoCommandFound 代表找不到此 plugin 在當前環境中可以執行的命令

func (*ErrNoCommandFound) Error

func (e *ErrNoCommandFound) Error() string

type ExitError

type ExitError struct {
	ExitStatus int
	// contains filtered or unexported fields
}

ExitError 代表有指定 exit status 的 error

type GitHub

type GitHub struct {
	Scopes []github.Scope `json:"scopes"`
}

GitHub 封裝了 GitHub-Repo 的相關資訊

type Metadata

type Metadata struct {
	Name              string   `json:"name"`
	Version           string   `json:"version"`
	Usage             string   `json:"usage"`
	Description       string   `json:"description"`
	Exec              Commands `json:"exec"`
	Hook              Commands `json:"hook"`
	IgnoreGlobalFlags bool     `json:"ignoreGlobalFlags"`
	GitHub            GitHub   `json:"github"`
}

Metadata 描述了 Plugin 相關的資訊

func (*Metadata) IsVersionGreaterThan

func (m *Metadata) IsVersionGreaterThan(other *Metadata) (bool, error)

IsVersionGreaterThan checks current version is greater than other.version

func (*Metadata) IsVersionLegal

func (m *Metadata) IsVersionLegal() bool

IsVersionLegal check is Version meet SemanticVersion2 spec, more details: https://semver.org/

type Platform

type Platform struct {
	Os      string `json:"os"`
	Arch    string `json:"arch"`
	Command string `json:"command"`
}

Platform 封裝了執行 plugin 執行命令的平台資訊

type Plugin

type Plugin struct {
	Metadata *Metadata
	Dir      string
	Source   string // 在安裝 plugin 時的 source, 只有非本機的 source 才會紀錄, 為了方便之後做 github plugin 的 upgrade
	Mount    string
}

Plugin 代表此 app 可以使用的插件

func LoadAll

func LoadAll(basedir string) ([]*Plugin, error)

LoadAll 載入 basedir 中的所有子目錄 plugin (子目錄只會收尋一層)

func LoadDir

func LoadDir(dirname string) (*Plugin, error)

LoadDir 載入 plugin 資料夾

func LoadPaths

func LoadPaths(paths string) ([]*Plugin, error)

LoadPaths 將傳入的 paths 以 filepath.SplitList 切割後, 依序呼叫 LoadAll 載入所有 plugin

func (*Plugin) FromGitHub

func (p *Plugin) FromGitHub() bool

FromGitHub 代表 plugin 的來源為 GitHub

func (*Plugin) Open

func (p *Plugin) Open(app string) error

Open 開啟 plugin 的目錄或遠端網址

func (*Plugin) PrepareCommand

func (p *Plugin) PrepareCommand(command string, extraArgs []string) (main string, argv []string, err error)

PrepareCommand takes a Plugin.Command and prepares it for execution.

It merges extraArgs into any arguments supplied in the plugin. It returns the name of the command and an args array.

The result is suitable to pass to exec.Command.

func (*Plugin) SetupEnv

func (p *Plugin) SetupEnv(metadata *release.Metadata) (err error)

SetupEnv 載入 plugin env

func (*Plugin) Unmount

func (p *Plugin) Unmount() error

Unmount 解除 Plugin Mount Volume

type Repo

type Repo struct {
	Source      string
	Description string
}

Repo 代表 Plugin 的 GitHub-Repo 的來源跟描述

func (*Repo) Contains

func (r *Repo) Contains(filters ...string) bool

Contains 回傳此 Repo 是否包含任何傳入的 filters 文字

type Repository

type Repository struct {
	Repos   []Repo
	Expires time.Time
}

Repository 代表 GitHub-Repo plugin 的匯總

func LoadRepository

func LoadRepository(log *logrus.Logger, home paths.Home, org string, force bool) (r *Repository, err error)

LoadRepository 載入 Repository

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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