wings/command/root.go

69 lines
1.8 KiB
Go
Raw Normal View History

package command
import (
"path/filepath"
"strconv"
"github.com/spf13/viper"
"github.com/Pterodactyl/wings/api"
"github.com/Pterodactyl/wings/config"
2017-07-06 18:51:27 +00:00
"github.com/Pterodactyl/wings/constants"
"github.com/Pterodactyl/wings/control"
"github.com/Pterodactyl/wings/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
2017-07-06 18:51:27 +00:00
// RootCommand is the root command of wings
var RootCommand = &cobra.Command{
Use: "wings",
Short: "",
Long: "",
Run: run,
}
2017-08-31 21:59:35 +00:00
var configPath string
2017-08-31 21:59:35 +00:00
func init() {
RootCommand.Flags().StringVarP(&configPath, "config", "c", "./config.yml", "Allows to set the path of the configuration file.")
}
2017-07-06 18:51:27 +00:00
// Execute registers the RootCommand
func Execute() {
RootCommand.Execute()
}
func run(cmd *cobra.Command, args []string) {
2017-07-06 17:01:08 +00:00
tools.InitLogging()
log.Info("Loading configuration...")
2017-08-31 21:59:35 +00:00
if err := config.LoadConfiguration(configPath); err != nil {
log.WithError(err).Fatal("Failed to find configuration file")
}
tools.ConfigureLogging()
2017-07-06 17:01:08 +00:00
log.Info(` ____`)
log.Info(`__ Pterodactyl _____/___/_______ _______ ______`)
log.Info(`\_____\ \/\/ / / / __ / ___/`)
log.Info(` \___\ / / / / /_/ /___ /`)
log.Info(` \___/\___/___/___/___/___ /______/`)
2017-07-06 18:51:27 +00:00
log.Info(` /_______/ v` + constants.Version)
2017-07-06 17:01:08 +00:00
log.Info()
2017-07-06 17:01:08 +00:00
log.Info("Configuration loaded successfully.")
log.Info("Loading configured servers...")
if err := control.LoadServerConfigurations(filepath.Join(viper.GetString(config.DataPath), constants.ServersPath)); err != nil {
log.WithError(err).Error("Failed to load configured servers.")
}
if amount := len(control.GetServers()); amount == 1 {
log.Info("Loaded 1 server.")
} else {
log.Info("Loaded " + strconv.Itoa(amount) + " servers.")
}
log.Info("Starting api webserver...")
api := api.NewAPI()
api.Listen()
}