mirror of
https://github.com/iyear/tdl
synced 2025-01-08 11:57:55 +08:00
46 lines
889 B
Go
46 lines
889 B
Go
package extensions
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
//go:generate go-enum --values --names --flag --nocase
|
|
|
|
const Prefix = "tdl-"
|
|
|
|
// ExtensionType ENUM(github, local)
|
|
type ExtensionType string
|
|
|
|
type Extension interface {
|
|
Type() ExtensionType
|
|
Name() string // Extension Name without tdl- prefix
|
|
Path() string // Path to executable
|
|
URL() string
|
|
Owner() string
|
|
CurrentVersion() string
|
|
LatestVersion(ctx context.Context) string
|
|
UpdateAvailable(ctx context.Context) bool
|
|
}
|
|
|
|
type baseExtension struct {
|
|
path string
|
|
}
|
|
|
|
func (e baseExtension) Name() string {
|
|
s := strings.TrimPrefix(filepath.Base(e.path), Prefix)
|
|
s = strings.TrimSuffix(s, filepath.Ext(s))
|
|
return s
|
|
}
|
|
|
|
func (e baseExtension) Path() string {
|
|
return e.path
|
|
}
|
|
|
|
type manifest struct {
|
|
Owner string `json:"owner,omitempty"`
|
|
Repo string `json:"repo,omitempty"`
|
|
Tag string `json:"tag,omitempty"`
|
|
}
|