-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrapcmd.go
86 lines (70 loc) · 1.72 KB
/
bootstrapcmd.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
79
80
81
82
83
84
85
86
// Copyright (C) 2017, 2018 Damon Revoe. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
package main
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"path"
"github.com/spf13/cobra"
)
func bootstrapPackage(packageDir string, pd *packageDefinition) error {
fmt.Println("[bootstrap] " + pd.PackageName)
bootstrapCmd := exec.Command("./autogen.sh")
bootstrapCmd.Dir = packageDir
bootstrapCmd.Stdout = os.Stdout
bootstrapCmd.Stderr = os.Stderr
if err := bootstrapCmd.Run(); err != nil {
return errors.New(path.Join(packageDir,
"autogen.sh") + ": " + err.Error())
}
return nil
}
func bootstrapPackages(args []string) error {
ws, err := loadWorkspace()
if err != nil {
return err
}
pi, err := readPackageDefinitions(ws.wp)
if err != nil {
return err
}
var selection packageDefinitionList
if len(args) > 0 {
selection, err = packageRangesToFlatSelection(pi, args)
} else {
selection, err = readPackageSelection(pi, ws.absPrivateDir)
}
if err != nil {
return err
}
pkgRootDir := ws.generatedPkgRootDir()
for _, pd := range selection {
err = bootstrapPackage(
path.Join(pkgRootDir, pd.PackageName), pd)
if err != nil {
return err
}
}
return nil
}
// bootstrapCmd represents the bootstrap command
var bootstrapCmd = &cobra.Command{
Use: "bootstrap [package_range...]",
Short: "Bootstrap all selected packages " +
"or the specified package range",
Run: func(_ *cobra.Command, args []string) {
if err := bootstrapPackages(args); err != nil {
log.Fatal(err)
}
},
}
func init() {
rootCmd.AddCommand(bootstrapCmd)
bootstrapCmd.Flags().SortFlags = false
addQuietFlag(bootstrapCmd)
addWorkspaceDirFlag(bootstrapCmd)
}