erigon-pulse/cmd/headers/commands/root.go
Evgeny Danilenko 74847d77e6
Rename to Erigon (#2018)
* turbo-geth to erigon

* tg, turbo to erigon
2021-05-26 11:35:39 +01:00

70 lines
1.4 KiB
Go

package commands
import (
"context"
"fmt"
"os"
"os/signal"
"path"
"syscall"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/internal/debug"
"github.com/ledgerwatch/erigon/log"
"github.com/spf13/cobra"
)
var (
sentryAddr string // Address of the sentry <host>:<port>
chaindata string // Path to chaindata
datadir string // Path to td working dir
)
func init() {
utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricFlags...))
}
func rootContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(ch)
select {
case <-ch:
log.Info("Got interrupt, shutting down...")
case <-ctx.Done():
}
cancel()
}()
return ctx
}
var rootCmd = &cobra.Command{
Use: "headers",
Short: "headers is Proof Of Concept for new header/block downloading algorithms",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if err := debug.SetupCobra(cmd); err != nil {
panic(err)
}
if chaindata == "" {
chaindata = path.Join(datadir, "erigon", "chaindata")
}
//if snapshotDir == "" {
// snapshotDir = path.Join(datadir, "erigon", "snapshot")
//}
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
debug.Exit()
},
}
func Execute() {
if err := rootCmd.ExecuteContext(rootContext()); err != nil {
fmt.Println(err)
os.Exit(1)
}
}