Some checks failed
Create Release & Upload Assets / Upload Assets To Gitea w/ goreleaser (push) Failing after 9s
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/liamg/tml"
|
|
"github.com/spf13/cobra"
|
|
|
|
"uberbringer/config"
|
|
"uberbringer/service"
|
|
)
|
|
|
|
var rootCommand = &cobra.Command{
|
|
Use: "uberbringer",
|
|
Short: "Runs the Überbringer daemon.",
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
config.GetConfig()
|
|
startSplash()
|
|
},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
startServer()
|
|
},
|
|
}
|
|
|
|
var versionCommand = &cobra.Command{
|
|
Use: "version",
|
|
Short: "Prints the current executable version and exits.",
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
fmt.Printf("%s | Version: %s Build: %s | Copyright © %d William Gill\n", config.Project, config.Version, config.Build, time.Now().Year())
|
|
},
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCommand.Execute(); err != nil {
|
|
log.Fatalf("failed to execute command: %s", err)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
rootCommand.PersistentFlags().StringVarP(&config.TOML, "config", "c", "config.toml", "Specify daemon config file.")
|
|
|
|
rootCommand.AddCommand(versionCommand)
|
|
}
|
|
|
|
func startSplash() {
|
|
|
|
//// ***** Start Console Splash ***** ////
|
|
tml.Printf("-----------------------------------------------------------------------------------------------\n\n")
|
|
tml.Printf("<bold> <lightblue>" + config.Project + " | Version: " + config.Version + " Build: " + config.Build + " | Copyright © " + strconv.Itoa(time.Now().Year()) + " William Gill</lightblue> <lightgreen> </bold>\n\n")
|
|
tml.Printf("<bold> <lightblue>Project:</lightblue> " + config.Project + "</bold>\n")
|
|
tml.Printf("<bold> <lightblue>Description:</lightblue> " + config.Description + "</bold>\n")
|
|
tml.Printf("<bold> <lightblue>Authors:</lightblue> " + config.Authors + "</bold>\n\n")
|
|
|
|
tml.Printf("-----------------------------------------------------------------------------------------------\n")
|
|
|
|
tml.Printf("<bold><cyan>[" + config.Project + "]: Initializing...</cyan></bold>\n")
|
|
//// ***** End Console Splash ***** ////
|
|
|
|
}
|
|
|
|
func startServer() {
|
|
|
|
//// ***** Start Echo ***** ////
|
|
tml.Printf("<bold><cyan>[" + config.Project + "]: Initializing Web Server...</cyan></bold>\n")
|
|
|
|
serverChannel := make(chan bool)
|
|
defer close(serverChannel)
|
|
// Start Web Server
|
|
go service.StartEcho(serverChannel, config.WebServerBindIP, config.WebServerPort)
|
|
// Stream Channel
|
|
serverData := <-serverChannel
|
|
fmt.Scanln(serverData)
|
|
|
|
//// ***** End Echo ***** ////
|
|
|
|
}
|