-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
build.go
59 lines (44 loc) · 1.11 KB
/
build.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
package cmd
import (
"context"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/c9s/bbgo/pkg/bbgo"
)
func init() {
RootCmd.AddCommand(BuildCmd)
}
var BuildCmd = &cobra.Command{
Use: "build",
Short: "build cross-platform binary",
// SilenceUsage is an option to silence usage when an error occurs.
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
configFile, err := cmd.Flags().GetString("config")
if err != nil {
return err
}
if len(configFile) == 0 {
return errors.New("--config option is required")
}
userConfig, err := bbgo.LoadBuildConfig(configFile)
if err != nil {
return err
}
if userConfig.Build == nil {
return errors.New("build config is not defined")
}
for _, target := range userConfig.Build.Targets {
log.Infof("building %s ...", target.Name)
binary, err := bbgo.BuildTarget(ctx, userConfig, target)
if err != nil {
return err
}
log.Infof("build succeeded: %s", binary)
}
return nil
},
}