51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package adapter
|
||
|
||
import (
|
||
"fmt"
|
||
"os"
|
||
|
||
"skillmgr/internal/types"
|
||
)
|
||
|
||
// PlatformAdapter 平台适配器接口
|
||
type PlatformAdapter interface {
|
||
// GetSkillInstallPath 获取 skill 安装路径
|
||
GetSkillInstallPath(scope types.Scope, skillName string) (string, error)
|
||
|
||
// GetCommandInstallPath 获取 command 安装路径
|
||
GetCommandInstallPath(scope types.Scope, commandGroup string) (string, error)
|
||
|
||
// AdaptSkill 适配 skill(返回 source → dest 映射)
|
||
AdaptSkill(sourcePath, destBasePath string) (map[string]string, error)
|
||
|
||
// AdaptCommand 适配 command(返回 source → dest 映射)
|
||
AdaptCommand(sourcePath, destBasePath, commandGroup string) (map[string]string, error)
|
||
}
|
||
|
||
// GetAdapter 获取平台适配器
|
||
func GetAdapter(platform types.Platform) (PlatformAdapter, error) {
|
||
switch platform {
|
||
case types.PlatformClaude:
|
||
return &ClaudeAdapter{}, nil
|
||
case types.PlatformOpenCode:
|
||
return &OpenCodeAdapter{}, nil
|
||
default:
|
||
return nil, fmt.Errorf("不支持的平台: %s", platform)
|
||
}
|
||
}
|
||
|
||
// getBasePath 获取基础路径
|
||
// 支持通过环境变量 SKILLMGR_TEST_BASE 覆盖(用于测试隔离)
|
||
func getBasePath(scope types.Scope) (string, error) {
|
||
// 测试模式:使用环境变量指定的目录
|
||
if testBase := os.Getenv("SKILLMGR_TEST_BASE"); testBase != "" {
|
||
return testBase, nil
|
||
}
|
||
|
||
// 生产模式
|
||
if scope == types.ScopeGlobal {
|
||
return os.UserHomeDir()
|
||
}
|
||
return os.Getwd()
|
||
}
|