-
Notifications
You must be signed in to change notification settings - Fork 2
/
command_record.go
78 lines (67 loc) · 1.59 KB
/
command_record.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package jambon
import (
"fmt"
"strings"
"github.com/b1naryth1ef/jambon/tacview"
"github.com/urfave/cli/v2"
)
// CommandRecord handles recording TacView files from a real-time server
var CommandRecord = cli.Command{
Name: "record",
Description: "record a tacview acmi file from a real time server",
Action: commandRecord,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "server",
Usage: "connection string for the TacView realtime server",
Required: true,
},
&cli.PathFlag{
Name: "output",
Usage: "path to the output ACMI file",
Required: true,
},
&cli.StringFlag{
Name: "username",
Usage: "username to use when connecting to the realtime server",
Value: "jambon-record",
},
&cli.StringFlag{
Name: "password",
Usage: "password to use when connecting to the realtime server",
Value: "",
},
},
}
func commandRecord(ctx *cli.Context) error {
serverStr := ctx.String("server")
if strings.Index(serverStr, ":") == -1 {
serverStr = fmt.Sprintf("%s:42674", serverStr)
}
reader, err := tacview.NewRealTimeReader(serverStr, ctx.String("username"), ctx.String("password"))
if err != nil {
return err
}
outputFile, err := openWritableTacView(ctx.Path("output"))
if err != nil {
return err
}
writer, err := tacview.NewWriter(outputFile, &reader.Header)
if err != nil {
return err
}
defer writer.Close()
data := make(chan *tacview.TimeFrame, 1)
go reader.ProcessTimeFrames(1, data)
for {
frame, ok := <-data
if !ok {
break
}
err = writer.WriteTimeFrame(frame)
if err != nil {
return err
}
}
return nil
}