~welt/murse

ref: v0.0.2 murse/main.go -rw-r--r-- 2.1 KiB
0bddb9ccwelt Revert default thread count. 5 months ago
                                                                                
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
package main

import (
	"os"

	"github.com/integrii/flaggy"
)

func main() {
	url := "https://toast.openfortress.fun/toast/"
	var threads int = 6
	var dir string
	var dry bool
	var http2 bool
	var repair bool

	upgrade := flaggy.NewSubcommand("upgrade")
	upgrade.Description = "Upgrades your game files to the latest version."
	upgrade.String(&url, "u", "url", "URL of TVS repository with a slash at the end.")
	upgrade.Int(&threads, "c", "threads", "Number of threads to use for downloading, minimum two.")
	upgrade.Bool(&http2, "2", "http2", "Enables HTTP/2, may cause problems with the servers but is faster.")
	upgrade.AddPositionalValue(&dir, "directory", 1, true, "Directory of game files.")
	flaggy.AttachSubcommand(upgrade, 1)

	verify := flaggy.NewSubcommand("verify")
	verify.Description = "Verifies an installation's files."
	verify.AddPositionalValue(&dir, "directory", 1, true, "Directory of game files.")
	verify.String(&url, "u", "url", "URL of TVS repository with a slash at the end.")
	verify.Bool(&repair, "r", "repair", "Repair the files where problems are found automatically.")
	verify.Bool(&http2, "2", "http2", "Enables HTTP/2, may cause problems with the servers but is faster.")
	flaggy.AttachSubcommand(verify, 1)

	var tvsdir string
	toast := flaggy.NewSubcommand("toast")
	toast.Description = "Toasts files. Don't use this unless you know what you're doing."
	toast.AddPositionalValue(&dir, "game files", 1, true, "Directory of game files to reference.")
	toast.AddPositionalValue(&tvsdir, "tvs directory", 2, true, "Directory of TVS folder to add changes to.")
	toast.Bool(&dry, "d", "dry", "Runs the command, but doesn't write any changes.")
	flaggy.AttachSubcommand(toast, 1)

	flaggy.SetVersion(VERSION)

	flaggy.Parse()

	if upgrade.Used {
		if threads < 2 {
			flaggy.ShowHelp("Must have at least two threads.")
			os.Exit(1)
		}
		os.Exit(upgradeMain(dir, url, threads, http2))
	}

	if verify.Used {
		os.Exit(verifyMain(dir, url, repair, http2))
	}

	if toast.Used {
		os.Exit(toastMain(dir, tvsdir, dry))
	}

	flaggy.ShowHelp("Please choose a subcommand.")
	os.Exit(1)
}