init
This commit is contained in:
57
internal/platform/platform.go
Normal file
57
internal/platform/platform.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// Platform 平台适配接口
|
||||
type Platform interface {
|
||||
// OS 返回操作系统标识
|
||||
OS() string
|
||||
|
||||
// Arch 返回架构标识
|
||||
Arch() string
|
||||
|
||||
// HomeDir 返回用户主目录
|
||||
HomeDir() string
|
||||
|
||||
// ConfigDir 返回配置文件目录
|
||||
ConfigDir() string
|
||||
|
||||
// DataDir 返回数据目录
|
||||
DataDir() string
|
||||
|
||||
// GetEnvVar 获取环境变量
|
||||
GetEnvVar(key string) string
|
||||
|
||||
// SetEnvVar 设置用户级环境变量
|
||||
SetEnvVar(ctx context.Context, key, value string) error
|
||||
|
||||
// AddToPath 添加目录到 PATH
|
||||
AddToPath(ctx context.Context, dir string) error
|
||||
|
||||
// IsAdmin 是否以管理员身份运行
|
||||
IsAdmin() bool
|
||||
|
||||
// PackageManagers 返回可用的包管理器名称
|
||||
PackageManagers() []string
|
||||
|
||||
// DefaultShell 返回默认 Shell
|
||||
DefaultShell() string
|
||||
}
|
||||
|
||||
// Detect 检测当前平台并返回对应的 Platform 实现
|
||||
func Detect() Platform {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
return NewWindowsPlatform()
|
||||
case "darwin":
|
||||
return NewDarwinPlatform()
|
||||
case "linux":
|
||||
return NewLinuxPlatform()
|
||||
default:
|
||||
// Fallback to Linux
|
||||
return NewLinuxPlatform()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user