Skip to content

Commit

Permalink
lazy initialization at start
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
  • Loading branch information
aluzzardi committed Oct 30, 2018
1 parent 2f51b17 commit 4f61964
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 0 additions & 10 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -42,7 +41,6 @@ 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 {
Expand All @@ -51,14 +49,6 @@ func create(name, rootDir string) {

build(name, rootDir, false)

ui.Info("Generating configuration and gensis")
if err := dockerRun(ctx, rootDir, name, "init"); err != nil {
ui.Fatal("Initialization failed: %v", err)
}
if err := ui.Tree(path.Join(rootDir, "data"), nil); err != nil {
ui.Fatal("%v", err)
}

ui.Success("Sucess! Created %s at %s", ui.Emphasize(name), ui.Emphasize(rootDir))
printGettingStarted(name)
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"context"
"os"
"path"
"path/filepath"
"time"

Expand Down Expand Up @@ -45,6 +47,18 @@ func startExplorer(ctx context.Context, name, rootDir string) {
func start(name, rootDir string) {
ctx, cancel := context.WithCancel(context.Background())
ui.Info("Starting %s", name)

// Initialize if needed.
if _, err := os.Stat(path.Join(rootDir, "data")); os.IsNotExist(err) {
ui.Info("Generating configuration and gensis")
if err := dockerRun(ctx, rootDir, name, "init"); err != nil {
ui.Fatal("Initialization failed: %v", err)
}
if err := ui.Tree(path.Join(rootDir, "data"), nil); err != nil {
ui.Fatal("%v", err)
}
}

ui.Success("Application is live at: %s", ui.Emphasize("http://localhost:26657/"))
ui.Success("Cosmos Explorer is live at: %s", ui.Emphasize("http://localhost:8080/"))
defer cancel()
Expand Down

0 comments on commit 4f61964

Please sign in to comment.