feat: add skill management service
This commit is contained in:
121
app.go
121
app.go
@@ -2,26 +2,127 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sgg-ai-skill-manager/internal/domain"
|
||||
"sgg-ai-skill-manager/internal/service"
|
||||
)
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
ctx context.Context
|
||||
service *service.Service
|
||||
initErr error
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
svc, err := service.NewDefault()
|
||||
return &App{service: svc, initErr: err}
|
||||
}
|
||||
|
||||
// startup is called when the app starts. The context is saved
|
||||
// so we can call the runtime methods
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
if a.service != nil {
|
||||
a.service.StartAutoUpdate(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// Greet returns a greeting for the given name
|
||||
func (a *App) Greet(name string) string {
|
||||
return fmt.Sprintf("Hello %s, It's show time!", name)
|
||||
func (a *App) LoadConfig() (domain.Config, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return domain.Config{}, err
|
||||
}
|
||||
return a.service.LoadConfig()
|
||||
}
|
||||
|
||||
func (a *App) SaveConfig(req domain.SaveConfigRequest) error {
|
||||
if err := a.ready(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.service.SaveConfig(a.context(), req)
|
||||
}
|
||||
|
||||
func (a *App) TestConnection(req domain.SaveConfigRequest) (domain.TestConnectionResult, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return domain.TestConnectionResult{}, err
|
||||
}
|
||||
return a.service.TestConnection(a.context(), req)
|
||||
}
|
||||
|
||||
func (a *App) ListRemoteSkills() ([]domain.RemoteSkill, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.service.ListRemoteSkills(a.context())
|
||||
}
|
||||
|
||||
func (a *App) ListLocalSkills() ([]domain.SkillState, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.service.ListLocalSkills(a.context())
|
||||
}
|
||||
|
||||
func (a *App) DownloadSkill(repo domain.RemoteSkill) (domain.SkillState, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return domain.SkillState{}, err
|
||||
}
|
||||
return a.service.DownloadSkill(a.context(), repo)
|
||||
}
|
||||
|
||||
func (a *App) UpdateSkill(org, repo string) (domain.SkillState, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return domain.SkillState{}, err
|
||||
}
|
||||
return a.service.UpdateSkill(a.context(), org, repo)
|
||||
}
|
||||
|
||||
func (a *App) InstallSkill(org, repo, targetID string) (domain.SkillState, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return domain.SkillState{}, err
|
||||
}
|
||||
return a.service.InstallSkill(a.context(), org, repo, targetID)
|
||||
}
|
||||
|
||||
func (a *App) UninstallSkill(org, repo, targetID string) (domain.SkillState, error) {
|
||||
if err := a.ready(); err != nil {
|
||||
return domain.SkillState{}, err
|
||||
}
|
||||
return a.service.UninstallSkill(a.context(), org, repo, targetID)
|
||||
}
|
||||
|
||||
func (a *App) DeleteSkill(org, repo string) error {
|
||||
if err := a.ready(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.service.DeleteSkill(a.context(), org, repo)
|
||||
}
|
||||
|
||||
func (a *App) OpenInVSCode(org, repo string) error {
|
||||
if err := a.ready(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.service.OpenInVSCode(a.context(), org, repo)
|
||||
}
|
||||
|
||||
func (a *App) OpenFolder(org, repo string) error {
|
||||
if err := a.ready(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.service.OpenFolder(a.context(), org, repo)
|
||||
}
|
||||
|
||||
func (a *App) RunAutoUpdate() error {
|
||||
if err := a.ready(); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.service.RunAutoUpdate(a.context())
|
||||
}
|
||||
|
||||
func (a *App) ready() error {
|
||||
return a.initErr
|
||||
}
|
||||
|
||||
func (a *App) context() context.Context {
|
||||
if a.ctx == nil {
|
||||
return context.Background()
|
||||
}
|
||||
return a.ctx
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user