-
Notifications
You must be signed in to change notification settings - Fork 13
/
list.go
78 lines (65 loc) · 2.04 KB
/
list.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package platforms
import (
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
"github.com/go-openapi/strfmt"
)
// List manages the listing execution context.
type List struct {
out output.Outputer
proj *project.Project
auth *authentication.Auth
}
// NewList prepares a list execution context for use.
func NewList(prime primeable) *List {
return &List{
out: prime.Output(),
proj: prime.Project(),
auth: prime.Auth(),
}
}
// Run executes the list behavior.
func (l *List) Run() error {
logging.Debug("Execute platforms list")
if l.proj == nil {
return rationalize.ErrNoProject
}
commitID, err := localcommit.Get(l.proj.Dir())
if err != nil {
return errs.Wrap(err, "Unable to get local commit")
}
targetCommitID, err := targetedCommitID(commitID.String(), l.proj.Name(), l.proj.Owner(), l.proj.BranchName())
if err != nil {
return errs.Wrap(err, "Unable to get commit ID")
}
modelPlatforms, err := model.FetchPlatformsForCommit(*targetCommitID, l.auth)
if err != nil {
return errs.Wrap(err, "Unable to get platforms for commit")
}
platforms := makePlatformsFromModelPlatforms(modelPlatforms)
var plainOutput interface{} = platforms
if len(platforms) == 0 {
plainOutput = locale.Tl("platforms_list_no_platforms", "There are no platforms for this project.")
}
l.out.Print(output.Prepare(plainOutput, platforms))
return nil
}
func targetedCommitID(commitID, projName, projOrg, branchName string) (*strfmt.UUID, error) {
if commitID != "" {
var cid strfmt.UUID
err := cid.UnmarshalText([]byte(commitID))
return &cid, err
}
latest, err := model.BranchCommitID(projOrg, projName, branchName)
if err != nil {
return nil, err
}
return latest, nil
}