-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
75 lines (64 loc) · 1.74 KB
/
main.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
package main
// SPDX-FileCopyrightText: © Moritz Poldrack & AUTHORS
// SPDX-License-Identifier: AGPL-3.0-or-later
import (
"fmt"
"net/url"
"os"
"path/filepath"
"git.sr.ht/~poldi1405/glog"
cli "github.com/jawher/mow.cli"
)
// Version is filled with the programs version at compile time
var Version = "0.2.1"
func main() {
defer glog.PanicHandler()
glog.SetLevel(glog.INFO)
glog.Infof("starting uniview version %s", Version)
if filepath.Base(os.Args[0]) == "univiewd" {
glog.Debug("starting in server mode")
err := startServer()
if err != nil {
glog.Errorf("failed to start server: %v", err)
os.Exit(1)
}
glog.Debug("server has shut down")
return
}
app := cli.App("uniview", "synchronise video playback")
app.Spec = "([--insecure] SERVER ROOM FILE) | URL"
var server, room, file, rawurl string
var insecure bool
app.StringArgPtr(&server, "SERVER", "", "the server to connect to")
app.StringArgPtr(&room, "ROOM", "", "the room to join")
app.StringArgPtr(&file, "FILE", "", "the file to open")
app.BoolOptPtr(&insecure, "i insecure", false, "do not validate the server certificate")
app.StringArgPtr(&rawurl, "URL", "", "the uniview:// address to connect to")
app.Action = func() {
var err error
var u *url.URL
if len(rawurl) == 0 {
rawurl = fmt.Sprintf("uniview://%s/%s", server, room)
u, err = url.Parse(rawurl)
q := u.Query()
q.Add("file", file)
if insecure {
q.Add("insecure", "")
}
u.RawQuery = q.Encode()
} else {
u, err = url.Parse(rawurl)
}
if err != nil {
glog.Errorf("failed to parse URL: %v", err)
os.Exit(1)
}
glog.Debugf("connecting to %s", u)
err = startClient(u)
if err != nil {
glog.Errorf("failed to start server: %v", err)
os.Exit(1)
}
}
app.Run(os.Args)
}