add cmdline argument to start in a specific channel
[barnard.git] / main.go
1 package main
2
3 import (
4         "crypto/tls"
5         "flag"
6         "fmt"
7         "os"
8
9         "layeh.com/barnard/uiterm"
10         "layeh.com/gumble/gumble"
11         _ "layeh.com/gumble/opus"
12 )
13
14 func main() {
15         // Command line flags
16         server := flag.String("server", "localhost:64738", "the server to connect to")
17         username := flag.String("username", "", "the username of the client")
18         password := flag.String("password", "", "the password of the server")
19         insecure := flag.Bool("insecure", false, "skip server certificate verification")
20         certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
21         channel := flag.String("channel", "", "initial channel")
22
23         flag.Parse()
24
25         // Initialize
26         b := Barnard{
27                 Config:  gumble.NewConfig(),
28                 Address: *server,
29                 DefaultChannel: *channel,
30         }
31
32         b.Config.Username = *username
33         b.Config.Password = *password
34
35         if *insecure {
36                 b.TLSConfig.InsecureSkipVerify = true
37         }
38         if *certificate != "" {
39                 cert, err := tls.LoadX509KeyPair(*certificate, *certificate)
40                 if err != nil {
41                         fmt.Fprintf(os.Stderr, "%s\n", err)
42                         os.Exit(1)
43                 }
44                 b.TLSConfig.Certificates = append(b.TLSConfig.Certificates, cert)
45         }
46
47         b.Ui = uiterm.New(&b)
48         b.Ui.Run()
49 }