-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.go
65 lines (53 loc) · 1.72 KB
/
setup.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
package cli
import (
"fmt"
"strings"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/stepman/stepman"
"github.com/urfave/cli"
)
func setup(c *cli.Context) error {
// Input validation
steplibURI := c.String(CollectionKey)
if steplibURI == "" {
failf("No step collection specified")
}
copySpecJSONPath := c.String(CopySpecJSONKey)
if c.IsSet(LocalCollectionKey) {
log.Warnf("'local' flag is deprecated")
log.Warnf("use 'file://' prefix in steplib path instead")
fmt.Println()
}
if c.Bool(LocalCollectionKey) {
if !strings.HasPrefix(steplibURI, "file://") {
log.Warnf("Appending file path prefix (file://) to StepLib (%s)", steplibURI)
steplibURI = "file://" + steplibURI
log.Warnf("From now you can refer to this StepLib with URI: %s", steplibURI)
log.Warnf("For example, to delete StepLib call: `stepman delete --collection %s`", steplibURI)
}
}
return Setup(steplibURI, copySpecJSONPath, log.NewDefaultLogger(false))
}
// Setup ...
func Setup(steplibURI, copySpecJSONPath string, log stepman.Logger) error {
if steplibURI == "" {
return fmt.Errorf("no step library specified")
}
// Setup
if err := stepman.SetupLibrary(steplibURI, log); err != nil {
return fmt.Errorf("setup failed: %s", err)
}
// Copy spec.json
if copySpecJSONPath != "" {
route, found := stepman.ReadRoute(steplibURI)
if !found {
return fmt.Errorf("no route found for steplib (%s)", steplibURI)
}
sourceSpecJSONPth := stepman.GetStepSpecPath(route)
if err := command.CopyFile(sourceSpecJSONPth, copySpecJSONPath); err != nil {
return fmt.Errorf("failed to copy spec.json from (%s) to (%s): %s", sourceSpecJSONPth, copySpecJSONPath, err)
}
}
return nil
}