-
Notifications
You must be signed in to change notification settings - Fork 4
/
create.go
61 lines (49 loc) · 1.35 KB
/
create.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
package action
import (
"context"
"fmt"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app/lib/filesystem"
"projectforge.dev/projectforge/app/project"
)
func onCreate(ctx context.Context, params *Params) *Result {
ret := newResult(TypeCreate, params.Cfg, params.Logger)
path := params.Cfg.GetStringOpt("path")
if path == "" {
path = "."
}
if wipe, _ := params.Cfg.ParseBool("wipe", true, true); wipe {
fs := filesystem.NewFileSystem(".", params.Logger)
if fs.Exists(path) {
ret.AddLog("removing existing directory [%s]", path)
_ = fs.RemoveRecursive(path)
}
}
prj := projectFromCfg(project.NewProject(params.ProjectKey, path), params.Cfg)
if params.CLI {
err := cliProject(prj, params.MSvc.Keys())
if err != nil {
return ret.WithError(err)
}
}
params.ProjectKey = prj.Key
err := params.PSvc.Save(prj)
if err != nil {
return ret.WithError(err)
}
_, err = params.PSvc.Refresh()
if err != nil {
msg := fmt.Sprintf("unable to load newly created project from path [%s]", path)
return errorResult(errors.Wrap(err, msg), TypeCreate, params.Cfg, params.Logger)
}
ctx, pm, err := getPrjAndMods(ctx, params)
if err != nil {
return errorResult(err, TypeCreate, params.Cfg, params.Logger)
}
retS := onSlam(ctx, pm)
ret = ret.Merge(retS)
if ret.HasErrors() {
return ret
}
return fullBuild(prj, ret, params.Logger)
}