-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmanager.go
More file actions
146 lines (129 loc) · 3.16 KB
/
Copy pathmanager.go
File metadata and controls
146 lines (129 loc) · 3.16 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package managers
import (
"context"
"time"
)
type Manager interface {
Name() string
Ecosystem() string
Init(ctx context.Context) (*Result, error)
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)
Replace(ctx context.Context, pkg string, opts ReplaceOptions) (*Result, error)
Supports(cap Capability) bool
Capabilities() []Capability
}
type InstallOptions struct {
Frozen bool
Clean bool
Production bool
}
type AddOptions struct {
Version string
Dev bool
Optional bool
Exact bool
Workspace string
}
// ReplaceOptions redirects a dependency to a non-registry source for
// downstream testing. Exactly one of Path, Git, or Drop should be set;
// Ref is only valid alongside Git.
type ReplaceOptions struct {
Path string // local filesystem path
Git string // git repository URL
Ref string // branch, tag, or revision for Git
Drop bool // remove an existing replacement
Extra []string // raw arguments appended to the command
}
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
CapInit
CapReplacePath
CapReplaceGit
CapReplaceDrop
)
var capabilityNames = map[Capability]string{
CapInit: "init",
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",
CapReplacePath: "replace_path",
CapReplaceGit: "replace_git",
CapReplaceDrop: "replace_drop",
}
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
}