-
Notifications
You must be signed in to change notification settings - Fork 13
/
add.go
69 lines (58 loc) · 1.59 KB
/
add.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
package platforms
import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/internal/runbits/requirements"
"github.com/ActiveState/cli/pkg/platform/api/buildplanner/types"
"github.com/ActiveState/cli/pkg/platform/model"
)
// AddRunParams tracks the info required for running Add.
type AddRunParams struct {
Params
}
// Add manages the adding execution context.
type Add struct {
prime primeable
}
type primeable interface {
primer.Outputer
primer.Prompter
primer.Projecter
primer.Auther
primer.Configurer
primer.Analyticer
primer.SvcModeler
}
// NewAdd prepares an add execution context for use.
func NewAdd(prime primeable) *Add {
return &Add{
prime: prime,
}
}
// Run executes the add behavior.
func (a *Add) Run(ps AddRunParams) error {
logging.Debug("Execute platforms add")
params, err := prepareParams(ps.Params)
if err != nil {
return err
}
if a.prime.Project() == nil {
return rationalize.ErrNoProject
}
if err := requirements.NewRequirementOperation(a.prime).ExecuteRequirementOperation(
nil,
&requirements.Requirement{
Name: params.name,
Version: params.version,
Operation: types.OperationAdded,
BitWidth: params.BitWidth,
NamespaceType: &model.NamespacePlatform,
},
); err != nil {
return locale.WrapError(err, "err_add_platform", "Could not add platform.")
}
a.prime.Output().Notice(locale.Tr("platform_added", params.name, params.version))
return nil
}