-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanager.go
More file actions
124 lines (108 loc) · 2.4 KB
/
manager.go
File metadata and controls
124 lines (108 loc) · 2.4 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package managers
import (
"context"
"time"
)
type Manager interface {
Name() string
Ecosystem() string
Install(ctx context.Context, opts InstallOptions) (*Result, error)
Add(ctx context.Context, pkg string, opts AddOptions) (*Result, error)
Remove(ctx context.Context, pkg string) (*Result, error)
List(ctx context.Context) (*Result, error)
Outdated(ctx context.Context) (*Result, error)
Update(ctx context.Context, pkg string) (*Result, error)
Path(ctx context.Context, pkg string) (*PathResult, error)
Vendor(ctx context.Context) (*Result, error)
Resolve(ctx context.Context) (*Result, error)
Supports(cap Capability) bool
Capabilities() []Capability
}
type InstallOptions struct {
Frozen bool
Clean bool
Production bool
}
type AddOptions struct {
Dev bool
Optional bool
Exact bool
Workspace string
}
type Result struct {
Command []string
Stdout string
Stderr string
ExitCode int
Duration time.Duration
Cwd string
Context ExecContext
}
func (r *Result) Success() bool {
return r.ExitCode == 0
}
type PathResult struct {
Path string // extracted path to the package
Result *Result // underlying command result
}
type ExecContext int
const (
ContextProject ExecContext = iota
ContextGlobal
ContextWorkspace
)
type Capability int
const (
CapInstall Capability = iota
CapInstallFrozen
CapInstallClean
CapAdd
CapAddDev
CapAddOptional
CapRemove
CapUpdate
CapList
CapOutdated
CapAudit
CapWorkspace
CapJSONOutput
CapSBOMCycloneDX
CapSBOMSPDX
CapPath
CapVendor
CapResolve
)
var capabilityNames = map[Capability]string{
CapInstall: "install",
CapInstallFrozen: "install_frozen",
CapInstallClean: "install_clean",
CapAdd: "add",
CapAddDev: "add_dev",
CapAddOptional: "add_optional",
CapRemove: "remove",
CapUpdate: "update",
CapList: "list",
CapOutdated: "outdated",
CapAudit: "audit",
CapWorkspace: "workspace",
CapJSONOutput: "json_output",
CapSBOMCycloneDX: "sbom_cyclonedx",
CapSBOMSPDX: "sbom_spdx",
CapPath: "path",
CapVendor: "vendor",
CapResolve: "resolve",
}
func (c Capability) String() string {
if name, ok := capabilityNames[c]; ok {
return name
}
return "unknown"
}
func CapabilityFromString(s string) (Capability, bool) {
for cap, name := range capabilityNames {
if name == s {
return cap, true
}
}
return 0, false
}