nogui.go 591 Bytes
Newer Older
ElyKar's avatar
ElyKar committed
1
2
3
4
5
6
7
package cmd

import (
	"fmt"
	"os"
	"strconv"

8
9
	"dfss/dfssd/api"
	"dfss/dfssd/server"
ElyKar's avatar
ElyKar committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var noguiCmd = &cobra.Command{
	Use:   "nogui",
	Short: "start demonstrator without GUI",
	Run: func(cmd *cobra.Command, args []string) {
		addrPort := "0.0.0.0:" + strconv.Itoa(viper.GetInt("port"))

		fmt.Println("Listening on " + addrPort)
		fn := func(v *api.Log) {
			fmt.Printf("[%d] %s: %s\n", v.Timestamp, v.Identifier, v.Log)
		}
		err := server.Listen(addrPort, fn)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	},
}