~welt/murse

ref: f8c17e4d52ac735482a9d3d096f461520ff4e0b4 murse/main.go -rw-r--r-- 2.1 KiB
f8c17e4dwelt Remove -2, add -1. 4 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
64
65
66
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 http1 bool
	var repair bool
	var owGameInfo bool

	upgrade := flaggy.NewSubcommand("upgrade")
	upgrade.Description = DESC_UPGRADE
	upgrade.String(&url, "u", "url", DESC_REPO)
	upgrade.Int(&threads, "c", "threads", "Number of threads to use for downloading, minimum two.")
	upgrade.Bool(&http1, "1", "http1", DESC_HTTP1)
	upgrade.Bool(&owGameInfo, "G", "overwrite-gameinfo", "When upgrading in a directory named open_fortress, overwrite any existing gameinfo.txt file.")
	upgrade.AddPositionalValue(&dir, "directory", 1, true, DESC_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", DESC_REPO)
	verify.Bool(&http1, "1", "http1", DESC_HTTP1)
	verify.Bool(&repair, "r", "repair", "Repair the files where problems are found automatically.")
	verify.Bool(&owGameInfo, "G", "overwrite-gameinfo", "When repairing in a directory named open_fortress, overwrite any existing gameinfo.txt file.")
	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", DESC_DRY)
	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, http1, owGameInfo))
	}

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

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

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