Neale Pickett
·
2016-01-18
spongycli.go
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "flag"
7 "log"
8 "os"
9 "path/filepath"
10)
11
12var playback int
13var running bool = true
14
15func inputLoop(nw *Network) {
16 bf := bufio.NewScanner(os.Stdin)
17 for bf.Scan() {
18 line := bf.Bytes()
19 nw.Write(line)
20 }
21}
22
23func usage() {
24 fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS] NETDIR\n", os.Args[0])
25 fmt.Fprintf(os.Stderr, "\n")
26 fmt.Fprintf(os.Stderr, "NETDIR is the path to your IRC directory (see README)\n")
27 fmt.Fprintf(os.Stderr, "\n")
28 fmt.Fprintf(os.Stderr, "OPTIONS:\n")
29 flag.PrintDefaults()
30}
31
32func main() {
33 flag.Usage = usage
34 flag.IntVar(&playback, "playback", 0, "Number of lines to play back on startup")
35
36 flag.Parse()
37 if flag.NArg() != 1 {
38 usage()
39 os.Exit(2)
40 }
41 netDir, err := filepath.Abs(flag.Arg(0))
42 if err != nil {
43 log.Fatal(err)
44 }
45
46 nw := NewNetwork(netDir)
47 defer nw.Close()
48 go inputLoop(nw)
49
50 outq := make(chan string, 50) // to stdout
51 go nw.Tail(outq)
52 for line := range outq {
53 fmt.Println(line)
54 }
55}