/
build.go
51 lines (44 loc) · 1.22 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
package cmd
import (
"context"
"github.com/blocklayerhq/chainkit/builder"
"github.com/blocklayerhq/chainkit/project"
"github.com/blocklayerhq/chainkit/ui"
"github.com/spf13/cobra"
)
var buildCmd = &cobra.Command{
Use: "build",
Short: "Build the application",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
ui.Fatal("unable to resolve flag: %v", err)
}
noCache, err := cmd.Flags().GetBool("no-cache")
if err != nil {
ui.Fatal("unable to resolve flag: %v", err)
}
rootDir := getCwd(cmd)
p, err := project.Load(rootDir)
if err != nil {
ui.Fatal("%v", err)
}
b := builder.New(rootDir, p.Image)
opts := builder.BuildOpts{
Verbose: verbose,
NoCache: noCache,
}
ui.Info("Building %s", ui.Emphasize(p.Name))
if err := b.Build(ctx, opts); err != nil {
ui.Fatal("Failed to build the application: %v", err)
}
},
}
func init() {
buildCmd.Flags().String("cwd", ".", "specifies the current working directory")
buildCmd.Flags().BoolP("verbose", "v", false, "enable verbose mode")
buildCmd.Flags().Bool("no-cache", false, "disable caching")
rootCmd.AddCommand(buildCmd)
}