-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (47 loc) · 807 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
)
const (
MaxPeerCount = 60
)
var torrent *Torrent
func main() {
parseCliInput()
}
func parseCliInput() {
if len(os.Args) <= 1 {
usage := `
USAGE: torgo <task>
The torgo tasks are:
download <torrent file> Downloads the specified torrent
`
log.Fatal(usage)
}
switch os.Args[1] {
case "download":
download()
default:
errorMsg := fmt.Sprintf("We don't recognize the command: %v", os.Args[1])
log.Fatal(errorMsg)
}
}
func download() {
var err error
if len(os.Args) <= 2 {
log.Fatal("Please pass in the location of the .torrent file")
}
filename := os.Args[2]
torrent, err = NewTorrent(filename)
if err != nil {
log.Fatal(err)
}
err = torrent.Start()
if err != nil {
log.Fatal(err)
}
var input string
fmt.Scanln(&input)
}