-
Notifications
You must be signed in to change notification settings - Fork 13
/
show.go
62 lines (54 loc) · 1.55 KB
/
show.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 use
import (
"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/pkg/platform/runtime/setup"
"github.com/ActiveState/cli/pkg/platform/runtime/target"
"github.com/ActiveState/cli/pkg/project"
"github.com/ActiveState/cli/pkg/projectfile"
)
type Show struct {
out output.Outputer
cfg *config.Instance
}
func NewShow(prime primeable) *Show {
return &Show{
prime.Output(),
prime.Config(),
}
}
func (s *Show) Run() error {
projectDir := s.cfg.GetString(constants.GlobalDefaultPrefname)
if projectDir == "" {
return locale.NewInputError("err_use_show_no_default_project", "No project is being used.")
}
proj, err := project.FromPath(projectDir)
if err != nil {
if errs.Matches(err, &projectfile.ErrorNoProject{}) {
return locale.WrapError(err, "err_use_default_project_does_not_exist")
}
return locale.WrapError(err, "err_use_show_get_project", "Could not get your project.")
}
projectTarget := target.NewProjectTarget(proj, nil, "")
executables := setup.ExecDir(projectTarget.Dir())
s.out.Print(output.Prepare(
locale.Tr("use_show_project_statement",
proj.NamespaceString(),
projectDir,
executables,
),
&struct {
Namespace string `json:"namespace"`
Path string `json:"path"`
Executables string `json:"executables"`
}{
proj.NamespaceString(),
projectDir,
executables,
},
))
return nil
}