Skip to content
Snippets Groups Projects
Select Git revision
  • e6cf660056001771562ecad919346742b1367e51
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • plugin.go 1.08 KiB
    package cli
    
    import (
    	"fmt"
    	"os"
    	"sync"
    
    	"github.com/iotaledger/goshimmer/plugins/banner"
    	"github.com/iotaledger/hive.go/events"
    	"github.com/iotaledger/hive.go/node"
    	flag "github.com/spf13/pflag"
    )
    
    // PluginName is the name of the CLI plugin.
    const PluginName = "CLI"
    
    var (
    	// plugin is the plugin instance of the CLI plugin.
    	plugin  *node.Plugin
    	once    sync.Once
    	version = flag.BoolP("version", "v", false, "Prints the GoShimmer version")
    )
    
    // Plugin gets the plugin instance.
    func Plugin() *node.Plugin {
    	once.Do(func() {
    		plugin = node.NewPlugin(PluginName, node.Enabled)
    	})
    	return plugin
    }
    
    func init() {
    	plugin = Plugin()
    
    	for name, plugin := range node.GetPlugins() {
    		onAddPlugin(name, plugin.Status)
    	}
    
    	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)
    	}
    }