Skip to content

Commit

Permalink
builder cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <[email protected]>
  • Loading branch information
aluzzardi committed Nov 1, 2018
1 parent 32dbb61 commit b658a98
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
26 changes: 11 additions & 15 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var buildCmd = &cobra.Command{
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)
Expand All @@ -25,7 +27,15 @@ var buildCmd = &cobra.Command{

rootDir := getCwd(cmd)
name := filepath.Base(rootDir)
build(name, rootDir, verbose, noCache)

b := builder.New(rootDir, name)
opts := builder.BuildOpts{
Verbose: verbose,
NoCache: noCache,
}
if err := b.Build(ctx, opts); err != nil {
ui.Fatal("Failed to build the application: %v", err)
}
},
}

Expand All @@ -36,17 +46,3 @@ func init() {

rootCmd.AddCommand(buildCmd)
}

func build(name, rootDir string, verbose, noCache bool) {
ctx := context.Background()
ui.Info("Building %s", name)
b := builder.New(rootDir, name)
opts := builder.BuildOpts{
Verbose: verbose,
NoCache: noCache,
}
if err := b.Build(ctx, opts); err != nil {
ui.Fatal("Failed to build the application: %v", err)
}
ui.Success("Build successfull")
}
9 changes: 8 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
Expand All @@ -10,6 +11,7 @@ import (
"strings"
"text/template"

"github.com/blocklayerhq/chainkit/pkg/builder"
"github.com/blocklayerhq/chainkit/pkg/httpfs"
"github.com/blocklayerhq/chainkit/pkg/ui"
"github.com/blocklayerhq/chainkit/templates"
Expand Down Expand Up @@ -41,13 +43,18 @@ func init() {
}

func create(name, rootDir string) {
ctx := context.Background()

ui.Info("Creating a new blockchain app in %s", ui.Emphasize(rootDir))

if err := scaffold(name, rootDir); err != nil {
ui.Fatal("Failed to initialize: %v", err)
}

build(name, rootDir, false, false)
b := builder.New(rootDir, name)
if err := b.Build(ctx, builder.BuildOpts{}); err != nil {
ui.Fatal("Failed to build the application: %v", err)
}

ui.Success("Success! Created %s at %s", ui.Emphasize(name), ui.Emphasize(rootDir))
printGettingStarted(name)
Expand Down
2 changes: 2 additions & 0 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func New(rootDir, name string) *Builder {

// Build executes a build.
func (b *Builder) Build(ctx context.Context, opts BuildOpts) error {
ui.Info("Building %s", b.name)
args := []string{"build", "-t", b.name}
if opts.NoCache {
args = append(args, "--no-cache")
Expand Down Expand Up @@ -80,6 +81,7 @@ func (b *Builder) Build(ctx context.Context, opts BuildOpts) error {
return err
}

ui.Success("Build successfull")
return nil
}

Expand Down

0 comments on commit b658a98

Please sign in to comment.