netbird/cmd/root.go

57 lines
1.1 KiB
Go
Raw Normal View History

2021-05-01 12:45:37 +02:00
package cmd
import (
"fmt"
log "github.com/sirupsen/logrus"
2021-05-01 12:45:37 +02:00
"github.com/spf13/cobra"
"os"
"os/signal"
"syscall"
)
const (
ExitSetupFailed = 1
)
2021-05-01 12:45:37 +02:00
var (
configPath string
logLevel string
2021-05-01 12:45:37 +02:00
rootCmd = &cobra.Command{
Use: "wiretrustee",
Short: "",
Long: "",
}
)
// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
}
func init() {
rootCmd.PersistentFlags().StringVar(&configPath, "config", "/etc/wiretrustee/config.json", "Wiretrustee config file location to write new config to")
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "")
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(addPeerCmd)
2021-05-01 12:45:37 +02:00
rootCmd.AddCommand(upCmd)
rootCmd.AddCommand(signalCmd)
}
func SetupCloseHandler() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
fmt.Println("\r- Ctrl+C pressed in Terminal")
os.Exit(0)
}
func InitLog(logLevel string) {
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Errorf("efailed parsing log-level %s: %s", logLevel, err)
os.Exit(ExitSetupFailed)
}
log.SetLevel(level)
}