First commit with a basic mockserver for BeamNG stuff
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
// Package cmd will be the CLI of our BeamNG OG mockserver
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "bngmock",
|
||||
Short: "CLI for a BeamNG OG mockserver",
|
||||
Long: ``,
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringP("address", "a", "127.0.0.1", "Address for the UDP server")
|
||||
rootCmd.PersistentFlags().IntP("port", "p", 4444, "Port for the UDP server")
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ESilva15/BeamNGMockOg/mockserver"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func replayAction(cmd *cobra.Command, args []string) {
|
||||
inputFile, _ := cmd.Flags().GetString("input")
|
||||
address, _ := cmd.Flags().GetString("address")
|
||||
port, _ := cmd.Flags().GetInt("port")
|
||||
|
||||
if err := mockserver.Replay(address, port, inputFile); err != nil {
|
||||
fmt.Printf("Something went wrong while playing the file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// shelf
|
||||
var replayCmd = &cobra.Command{
|
||||
Use: "replay",
|
||||
Short: "replay -i <path-to-bin-file>",
|
||||
Long: `replay will store the data from the given UDP server to the
|
||||
filepath given by -i`,
|
||||
Args: nil,
|
||||
Run: replayAction,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(replayCmd)
|
||||
|
||||
replayCmd.PersistentFlags().StringP("input", "i", "nofile.bin", "input file for serving")
|
||||
}
|
||||
Reference in New Issue
Block a user