Documentation
¶
Index ¶
- Constants
- Variables
- func Cleanup(log *logrus.Logger, home paths.Home, force bool, dryRun bool) error
- func Create(lang string, plugin *Metadata, path string) (string, error)
- func IsGitHubRepo(source string) bool
- func IsLocalDirReference(source string) bool
- func IsLocalReference(source string) bool
- func IsSupportedArchive(source string) bool
- func LoadPluginCommands(metadata *release.Metadata) ([]*cobra.Command, error)
- type Commands
- type ErrNoCommandFound
- type ExitError
- type GitHub
- type Metadata
- type Platform
- type Plugin
- type Repo
- type Repository
Constants ¶
const MetadataFileName = "metadata.yaml"
MetadataFileName 定義了 metadata 的檔案名稱
const SourceFileName = ".source"
SourceFileName 定義了 source 的檔案名稱
Variables ¶
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/([^/]+)/([^/]+)[/]?$`) )
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 可以輸出給使用者參考
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 IsLocalDirReference ¶
IsLocalDirReference 回傳 source 是否為 local 路徑並且為一個資料夾, 如 C:\some-dir, 而不是 https://...
func IsLocalReference ¶
IsLocalReference 回傳 source 是否為 local 路徑 如 C:\some-path, 而不是 https://...
func IsSupportedArchive ¶
IsSupportedArchive 回傳 source 是否支援傳入的檔案路徑的副檔名
Types ¶
type Commands ¶
Commands 封裝了執行 plugin 的執行命令
func (*Commands) GetCommand ¶
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 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 ¶
IsVersionGreaterThan checks current version is greater than other.version
func (*Metadata) IsVersionLegal ¶
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 (*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.
type Repository ¶
Repository 代表 GitHub-Repo plugin 的匯總
func LoadRepository ¶
func LoadRepository(log *logrus.Logger, home paths.Home, org string, force bool) (r *Repository, err error)
LoadRepository 載入 Repository