-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_project.go
62 lines (50 loc) · 1.25 KB
/
model_project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gogh
import (
"errors"
"os"
"path"
"path/filepath"
)
// Project is the location of a repository in the local.
// It is a valid location, that never means "exist".
type Project struct {
root string
spec Spec
}
func (p Project) Root() string {
return p.root
}
func (p Project) Host() string { return p.spec.host }
func (p Project) Owner() string { return p.spec.owner }
func (p Project) Name() string { return p.spec.name }
func (p Project) FullLevels() []string {
return []string{p.root, p.spec.host, p.spec.owner, p.spec.name}
}
func (p Project) RelLevels() []string {
return p.spec.RelLevels()
}
func (p Project) FullFilePath() string {
return filepath.Join(p.FullLevels()...)
}
func (p Project) RelFilePath() string {
return filepath.Join(p.RelLevels()...)
}
func (p Project) RelPath() string {
return path.Join(p.RelLevels()...)
}
// CheckEntity checks the project is exist in the local file-system.
func (p Project) CheckEntity() error {
path := p.FullFilePath()
stat, err := os.Stat(path)
if err != nil {
return err
}
if !stat.IsDir() {
return errors.New("project is not dir")
}
return nil
}
// UNDONE: CheckEntityInFileSystem() support fs.FS
func NewProject(root string, spec Spec) Project {
return Project{root: root, spec: spec}
}