From 99a23614100fdb041e42c7929582f29b903fc579 Mon Sep 17 00:00:00 2001
From: Hans Moog <hm@mkjc.net>
Date: Tue, 25 Feb 2020 03:44:59 +0100
Subject: [PATCH] Feat: adjusted to new hive.go

---
 go.mod                      |  2 +-
 go.sum                      |  4 ++++
 main.go                     |  2 +-
 plugins/banner/plugin.go    |  2 +-
 plugins/cli/plugin.go       | 22 +++++++++++++++++++---
 plugins/config/plugin.go    | 14 +++++++++-----
 plugins/logger/plugin.go    | 16 +++++++++-------
 tools/relay-checker/main.go |  4 ++--
 8 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/go.mod b/go.mod
index e2a7ed63..3b6f9094 100644
--- a/go.mod
+++ b/go.mod
@@ -13,7 +13,7 @@ require (
 	github.com/googollee/go-engine.io v1.4.3-0.20190924125625-798118fc0dd2
 	github.com/googollee/go-socket.io v1.4.3-0.20191204093753-683f8725b6d0
 	github.com/gorilla/websocket v1.4.1
-	github.com/iotaledger/hive.go v0.0.0-20200222013046-8268a12f52cb
+	github.com/iotaledger/hive.go v0.0.0-20200225022819-32427644698a
 	github.com/iotaledger/iota.go v1.0.0-beta.14
 	github.com/kr/pretty v0.2.0 // indirect
 	github.com/kr/text v0.2.0 // indirect
diff --git a/go.sum b/go.sum
index becfd602..ecf2a987 100644
--- a/go.sum
+++ b/go.sum
@@ -141,6 +141,10 @@ github.com/iotaledger/hive.go v0.0.0-20200219224037-2d5f5238c0de h1:J9G9YWM5q7r3
 github.com/iotaledger/hive.go v0.0.0-20200219224037-2d5f5238c0de/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64=
 github.com/iotaledger/hive.go v0.0.0-20200222013046-8268a12f52cb h1:lLObap03uuF0RPSGHflpzIZIdKz2robq/rqT3b1ghqU=
 github.com/iotaledger/hive.go v0.0.0-20200222013046-8268a12f52cb/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64=
+github.com/iotaledger/hive.go v0.0.0-20200225021953-8c07d94b7c38 h1:QsBAGr1fPwxrzvvRB2zy27gxDmeBhiWN87LD37jd0ZQ=
+github.com/iotaledger/hive.go v0.0.0-20200225021953-8c07d94b7c38/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64=
+github.com/iotaledger/hive.go v0.0.0-20200225022819-32427644698a h1:ga4SOHLYzXNCC7qHxBN8lK4kng8Ffu2x2QB+yKolH2w=
+github.com/iotaledger/hive.go v0.0.0-20200225022819-32427644698a/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64=
 github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
 github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A=
 github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
diff --git a/main.go b/main.go
index b0c2b7d3..efcc34bc 100644
--- a/main.go
+++ b/main.go
@@ -27,7 +27,7 @@ import (
 )
 
 func main() {
-	cli.PrintVersion()
+	config.Init()
 
 	go http.ListenAndServe("localhost:6061", nil) // pprof Server for Debbuging Mutexes
 
diff --git a/plugins/banner/plugin.go b/plugins/banner/plugin.go
index 3d069628..b4e4b284 100644
--- a/plugins/banner/plugin.go
+++ b/plugins/banner/plugin.go
@@ -10,7 +10,7 @@ var PLUGIN = node.NewPlugin("Banner", node.Enabled, configure, run)
 
 const (
 	// AppVersion version number
-	AppVersion = "v0.1.1"
+	AppVersion = "v0.2.0"
 
 	// AppName app code name
 	AppName = "GoShimmer"
diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go
index eab5b9b0..da1b6141 100644
--- a/plugins/cli/plugin.go
+++ b/plugins/cli/plugin.go
@@ -1,16 +1,19 @@
 package cli
 
 import (
+	"fmt"
+	"os"
+
 	"github.com/iotaledger/hive.go/events"
 	"github.com/iotaledger/hive.go/node"
 	flag "github.com/spf13/pflag"
+
+	"github.com/iotaledger/goshimmer/plugins/banner"
 )
 
 var PLUGIN = node.NewPlugin("CLI", node.Enabled)
 
-func onAddPlugin(name string, status int) {
-	AddPluginStatus(node.GetPluginIdentifier(name), status)
-}
+var version = flag.BoolP("version", "v", false, "Prints the GoShimmer version")
 
 func init() {
 	for name, status := range node.GetPlugins() {
@@ -20,4 +23,17 @@ func init() {
 	node.Events.AddPlugin.Attach(events.NewClosure(onAddPlugin))
 
 	flag.Usage = printUsage
+
+	PLUGIN.Events.Init.Attach(events.NewClosure(onInit))
+}
+
+func onAddPlugin(name string, status int) {
+	AddPluginStatus(node.GetPluginIdentifier(name), status)
+}
+
+func onInit(*node.Plugin) {
+	if *version {
+		fmt.Println(banner.AppName + " " + banner.AppVersion)
+		os.Exit(0)
+	}
 }
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go
index 0bf459db..1cd94123 100644
--- a/plugins/config/plugin.go
+++ b/plugins/config/plugin.go
@@ -1,6 +1,7 @@
 package config
 
 import (
+	"github.com/iotaledger/hive.go/events"
 	"github.com/iotaledger/hive.go/logger"
 	"github.com/iotaledger/hive.go/node"
 	"github.com/iotaledger/hive.go/parameter"
@@ -31,8 +32,8 @@ var (
 	}
 )
 
-func Load() {
-	// do nothing - the config get's initialized during init()
+func Init() {
+	PLUGIN.Events.Init.Trigger(PLUGIN)
 }
 
 func init() {
@@ -40,9 +41,11 @@ func init() {
 	Node = viper.New()
 	Node.SetDefault(logger.ViperKey, defaultLoggerConfig)
 
-	if err := fetch(false); err != nil {
-		panic(err)
-	}
+	PLUGIN.Events.Init.Attach(events.NewClosure(func(*node.Plugin) {
+		if err := fetch(false); err != nil {
+			panic(err)
+		}
+	}))
 }
 
 // fetch fetches config values from a dir defined via CLI flag --config-dir (or the current working dir if not set).
@@ -50,6 +53,7 @@ func init() {
 // It automatically reads in a single config file starting with "config" (can be changed via the --config CLI flag)
 // and ending with: .json, .toml, .yaml or .yml (in this sequence).
 func fetch(printConfig bool, ignoreSettingsAtPrint ...[]string) error {
+	flag.Parse()
 	err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, true)
 	if err != nil {
 		return err
diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go
index 79d30596..d3f85693 100644
--- a/plugins/logger/plugin.go
+++ b/plugins/logger/plugin.go
@@ -1,21 +1,23 @@
 package logger
 
 import (
+	"github.com/iotaledger/goshimmer/plugins/config"
+	"github.com/iotaledger/hive.go/events"
 	"github.com/iotaledger/hive.go/logger"
 	"github.com/iotaledger/hive.go/node"
-
-	"github.com/iotaledger/goshimmer/plugins/config"
 )
 
 // define the plugin as a placeholder, so the init methods get executed accordingly
 var PLUGIN = node.NewPlugin("Logger", node.Enabled)
 
-func Load() {
-	// do nothing - the config get's initialized during init()
+func Init() {
+	PLUGIN.Events.Init.Trigger(PLUGIN)
 }
 
 func init() {
-	if err := logger.InitGlobalLogger(config.Node); err != nil {
-		panic(err)
-	}
+	PLUGIN.Events.Init.Attach(events.NewClosure(func(*node.Plugin) {
+		if err := logger.InitGlobalLogger(config.Node); err != nil {
+			panic(err)
+		}
+	}))
 }
diff --git a/tools/relay-checker/main.go b/tools/relay-checker/main.go
index 7518c76b..8e98efca 100644
--- a/tools/relay-checker/main.go
+++ b/tools/relay-checker/main.go
@@ -40,8 +40,8 @@ func testNodesGetTransactions(txnHash trinary.Hash) error {
 }
 
 func main() {
-	config.Load()
-	logger.Load()
+	config.Init()
+	logger.Init()
 
 	InitConfig()
 
-- 
GitLab