Skip to content
Snippets Groups Projects
Select Git revision
  • e9e1b66274186d047be87beeebe57fd66d627368
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

go.sum

Blame
  • This project manages its dependencies using Go Modules. Learn more
    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)
    	}
    }