init
This commit is contained in:
57
internal/config/paths.go
Normal file
57
internal/config/paths.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
// AppName 应用名称
|
||||
AppName = "devpack"
|
||||
|
||||
// DefaultConfigFileName 默认配置文件名
|
||||
DefaultConfigFileName = "config.yaml"
|
||||
|
||||
// DefaultProfileName 默认 Profile 名
|
||||
DefaultProfileName = "default"
|
||||
)
|
||||
|
||||
// Paths DevPack 路径管理
|
||||
type Paths struct {
|
||||
Home string // ~/.devpack
|
||||
Config string // ~/.devpack/config.yaml
|
||||
Profiles string // ~/.devpack/profiles
|
||||
Packs string // ~/.devpack/packs
|
||||
Logs string // ~/.devpack/logs
|
||||
Temp string // ~/.devpack/tmp
|
||||
}
|
||||
|
||||
// DefaultPaths 返回默认路径配置
|
||||
func DefaultPaths() (*Paths, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
devpackHome := filepath.Join(home, ".devpack")
|
||||
|
||||
return &Paths{
|
||||
Home: devpackHome,
|
||||
Config: filepath.Join(devpackHome, DefaultConfigFileName),
|
||||
Profiles: filepath.Join(devpackHome, "profiles"),
|
||||
Packs: filepath.Join(devpackHome, "packs"),
|
||||
Logs: filepath.Join(devpackHome, "logs"),
|
||||
Temp: filepath.Join(devpackHome, "tmp"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// EnsureDirs 确保所有目录存在
|
||||
func (p *Paths) EnsureDirs() error {
|
||||
dirs := []string{p.Home, p.Profiles, p.Packs, p.Logs, p.Temp}
|
||||
for _, dir := range dirs {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user