From 4f61964247f237fcbb563713b36f2be46618d4f9 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Tue, 30 Oct 2018 16:18:03 -0700 Subject: [PATCH] lazy initialization at start Signed-off-by: Andrea Luzzardi --- cmd/create.go | 10 ---------- cmd/start.go | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 800dd08..3d4414f 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -2,7 +2,6 @@ package cmd import ( "bytes" - "context" "fmt" "io/ioutil" "os" @@ -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 { @@ -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) } diff --git a/cmd/start.go b/cmd/start.go index bc69ef0..8ff4570 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -2,6 +2,8 @@ package cmd import ( "context" + "os" + "path" "path/filepath" "time" @@ -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()