~welt/murse

ref: v0.0.3 murse/main.go -rw-r--r-- 1.8 KiB
59f92316welt Move some command descriptions to constants, fix marshaler for realsies, and stop being anal about slashes. 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 = 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(&http2, "2", "http2", DESC_HTTP2)
	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(&repair, "r", "repair", "Repair the files where problems are found automatically.")
	verify.Bool(&http2, "2", "http2", DESC_HTTP2)
	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, 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)
}