This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGhostYgg.go
72 lines (62 loc) · 1.46 KB
/
GhostYgg.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
package main
import (
"flag"
"fmt"
"github.com/GuillaumeMCK/GhostYgg/tui"
"github.com/GuillaumeMCK/GhostYgg/utils"
"log"
"os"
"path/filepath"
)
var (
torrentFiles []string
output *string
helpFlag *bool
downloadFolder string
)
func init() {
torrentFiles = []string{}
// Filter all args that are not torrent files
for _, arg := range os.Args[1:] {
if filepath.Ext(arg) == ".torrent" {
torrentFiles = append(torrentFiles, arg)
}
}
output = flag.String("o", "", "Download directory")
helpFlag = flag.Bool("help", false, "Show this message")
// Define how to use the program
flag.Usage = func() {
fmt.Printf("GhostYgg - Torrent client\n\n")
fmt.Printf("Usage: %s file1.torrent file2.torrent ... [options]\n\n", os.Args[0])
fmt.Printf("Options:\n")
flag.PrintDefaults()
}
// Parse command-line flags
flag.Parse()
// If -help flag is set, show the usage and exit
if *helpFlag {
flag.Usage()
return
}
// Determine default download folder
defaultDownloadFolder, err := utils.GetDefaultDownloadFolder()
if err != nil {
log.Fatal(err)
}
// Use the value of -download-folder flag, or default download folder
downloadFolder = *output
if downloadFolder == "" {
downloadFolder = defaultDownloadFolder
}
// Make sure download folder exists
err = os.MkdirAll(downloadFolder, os.ModePerm)
if err != nil {
log.Fatal(err)
}
}
func main() {
err := tui.StartTUI(torrentFiles, downloadFolder)
if err != nil {
log.Fatal(err)
}
}