-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
438 lines (424 loc) · 12.9 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
// pap :)
package main
import (
"os"
"github.com/talwat/pap/internal/cmd"
"github.com/talwat/pap/internal/cmd/downloadcmds"
"github.com/talwat/pap/internal/cmd/plugincmds"
"github.com/talwat/pap/internal/cmd/plugincmds/generatecmds"
"github.com/talwat/pap/internal/cmd/propcmds"
"github.com/talwat/pap/internal/global"
"github.com/talwat/pap/internal/log"
"github.com/urfave/cli/v2"
)
//nolint:funlen,exhaustruct,maintidx // Ignoring these issues because this file only serves to define commands.
func main() {
app := &cli.App{
Name: "pap",
Usage: "a swiss army knife for minecraft servers",
Version: global.Version,
Authors: []*cli.Author{
{
Name: "talwat",
},
},
HideHelp: true,
HideVersion: true,
//nolint:lll
CustomAppHelpTemplate: `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}
VERSION:
{{.Version}}{{if .Description}}
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}
{{- if len .Authors}}
AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
COPYRIGHT:
{{template "copyrightTemplate" .}}{{end}}
`,
CommandNotFound: func(ctx *cli.Context, command string) {
log.RawError("command not found: %s", command)
},
OnUsageError: func(ctx *cli.Context, err error, isSubcommand bool) error {
log.RawError("%s", err)
return nil
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "assume-default",
Value: false,
Usage: "assume the default answer in all prompts",
Aliases: []string{"y"},
Destination: &global.AssumeDefaultInput,
},
&cli.BoolFlag{
Name: "debug",
Value: false,
Usage: "print extra information for debugging or troubleshooting",
Aliases: []string{"d"},
Destination: &global.Debug,
},
},
Commands: []*cli.Command{
{
Name: "download",
Aliases: []string{"d"},
Usage: "download a jarfile",
ArgsUsage: "[type]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "minecraft-version",
Value: "latest",
Usage: "the minecraft version to download",
Aliases: []string{"version", "v"},
Destination: &global.MinecraftVersionInput,
},
},
Subcommands: []*cli.Command{
{
Name: "paper",
Aliases: []string{"pa"},
Usage: "download a paper jarfile",
Action: downloadcmds.DownloadPaperCommand,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "paper-build",
Value: "latest",
Usage: "the papermc build to download",
Aliases: []string{"build", "b"},
Destination: &global.JarBuildInput,
},
&cli.BoolFlag{
Name: "paper-experimental",
Value: false,
Usage: "takes the latest build regardless",
Aliases: []string{"experimental", "e"},
Destination: &global.PaperExperimentalBuildInput,
},
&cli.StringFlag{
Name: "minecraft-version",
Value: "latest",
Usage: "the minecraft version to download",
Aliases: []string{"version", "v"},
Destination: &global.MinecraftVersionInput,
},
},
},
{
Name: "fabric",
Aliases: []string{"fa"},
Usage: "download a fabric jarfile",
Action: downloadcmds.DownloadFabricCommand,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "fabric-loader",
Value: "latest",
Usage: "the fabric loader version to use",
Aliases: []string{"loader", "l"},
Destination: &global.FabricLoaderVersion,
},
&cli.StringFlag{
Name: "fabric-installer",
Value: "latest",
Usage: "the fabric installer version to use",
Aliases: []string{"installer", "i"},
Destination: &global.FabricInstallerVersion,
},
&cli.BoolFlag{
Name: "fabric-loader-experimental",
Value: false,
Usage: "takes the latest loader version regardless",
Aliases: []string{"experimental", "e"},
Destination: &global.FabricExperimentalLoaderVersion,
},
&cli.BoolFlag{
Name: "minecraft-snapshot",
Value: false,
Usage: "takes the latest snapshot instead of the latest release",
Aliases: []string{"snapshot", "s"},
Destination: &global.UseSnapshotInput,
},
&cli.StringFlag{
Name: "minecraft-version",
Value: "latest",
Usage: "the minecraft version to download",
Aliases: []string{"version", "v"},
Destination: &global.MinecraftVersionInput,
},
},
},
{
Name: "purpur",
Aliases: []string{"pu"},
Usage: "download a purpur jarfile",
Action: downloadcmds.DownloadPurpurCommand,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "purpur-build",
Value: "latest",
Usage: "the papermc build to download",
Aliases: []string{"build", "b"},
Destination: &global.JarBuildInput,
},
&cli.StringFlag{
Name: "minecraft-version",
Value: "latest",
Usage: "the minecraft version to download",
Aliases: []string{"version", "v"},
Destination: &global.MinecraftVersionInput,
},
},
},
{
Name: "official",
Aliases: []string{"o"},
Usage: "download an official mojang jarfile",
Action: downloadcmds.DownloadOfficialCommand,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "minecraft-snapshot",
Value: false,
Usage: "takes the latest snapshot instead of the latest release",
Aliases: []string{"snapshot", "s"},
Destination: &global.UseSnapshotInput,
},
&cli.StringFlag{
Name: "minecraft-version",
Value: "latest",
Usage: "the minecraft version to download",
Aliases: []string{"version", "v"},
Destination: &global.MinecraftVersionInput,
},
},
},
{
Name: "forge",
Aliases: []string{"fo"},
Usage: "download a forge jarfile",
Action: downloadcmds.DownloadForgeCommand,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "download-latest",
Value: false,
Usage: "download the latest forge installer instead of a recommended version",
Aliases: []string{"latest", "l"},
Destination: &global.ForgeUseLatestInstaller,
},
&cli.StringFlag{
Name: "minecraft-version",
Value: "latest",
Usage: "the minecraft version to download",
Aliases: []string{"version", "v"},
Destination: &global.MinecraftVersionInput,
},
&cli.StringFlag{
Name: "installer-version",
Value: "latest",
Usage: "the forge installer version to download",
Aliases: []string{"installer", "i"},
Destination: &global.ForgeInstallerVersion,
},
},
},
},
},
{
Name: "geyser",
Aliases: []string{"g"},
Usage: "downloads geyser",
Action: cmd.GeyserCommand,
},
{
Name: "plugin",
Aliases: []string{"pl"},
Usage: "manages plugins",
ArgsUsage: "[install|uninstall] [plugin]",
Subcommands: []*cli.Command{
{
Name: "install",
Aliases: []string{"i"},
Usage: "installs a plugin",
Action: plugincmds.InstallCommand,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-deps",
Value: false,
Usage: "whether to install and calculate dependencies",
Aliases: []string{"no-dependencies"},
Destination: &global.NoDepsInput,
},
&cli.BoolFlag{
Name: "install-optional-deps",
Value: false,
Usage: "whether to install optional dependencies",
Aliases: []string{"optional"},
Destination: &global.InstallOptionalDepsInput,
},
&cli.BoolFlag{
Name: "plugin-experimental",
Value: false,
Usage: "takes the latest version regardless",
Aliases: []string{"experimental"},
Destination: &global.PluginExperimentalInput,
},
},
},
{
Name: "uninstall",
Aliases: []string{"u", "remove", "r"},
Usage: "get property",
Action: plugincmds.UninstallCommand,
},
{
Name: "info",
Aliases: []string{"in"},
Usage: "get information about a plugin",
Action: plugincmds.InfoCommand,
},
{
Name: "generate",
Aliases: []string{"gen", "g"},
Usage: "generate a plugin json file using a 3rd party plugin library",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "use-stdout",
Aliases: []string{"stdout", "s"},
Usage: "output to stdout instead of writing it to the disk",
Destination: &global.UseStdoutInput,
},
},
Subcommands: []*cli.Command{
{
Name: "modrinth",
Aliases: []string{"m"},
Usage: "generate a plugin json file using modrinth",
Action: generatecmds.GenerateModrinth,
},
{
Name: "spigotmc",
Aliases: []string{"s"},
Usage: "generate a plugin json file using spigotmc",
Action: generatecmds.GenerateSpigotMC,
},
{
Name: "bukkit",
Aliases: []string{"b"},
Usage: "generate a plugin json file using bukkit",
Action: generatecmds.GenerateBukkit,
},
},
},
},
},
{
Name: "script",
Aliases: []string{"sc"},
Usage: "generate a script to run the jarfile",
Action: cmd.ScriptCommand,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "mem",
Value: "2G",
Usage: "the value for -Xms and -Xmx in the run command",
Aliases: []string{"memory", "m"},
Destination: &global.MemoryInput,
},
&cli.BoolFlag{
Name: "aikars",
Value: false,
Usage: "whether to use aikars flags: https://docs.papermc.io/paper/aikars-flags",
Aliases: []string{"a"},
Destination: &global.AikarsInput,
},
&cli.StringFlag{
Name: "jar",
Usage: "the name for the server jarfile",
Aliases: []string{"j"},
Destination: &global.JarInput,
},
&cli.BoolFlag{
Name: "use-gui",
Aliases: []string{"gui"},
Usage: "whether to use the GUI or not",
Destination: &global.GUIInput,
},
&cli.BoolFlag{
Name: "use-stdout",
Aliases: []string{"stdout", "s"},
Usage: "output to stdout instead of writing it to the disk",
Destination: &global.UseStdoutInput,
},
},
},
{
Name: "update",
Aliases: []string{"u"},
Usage: "updates pap if there is a new version available",
Action: cmd.UpdateCommand,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "reinstall",
Aliases: []string{"r"},
Usage: "reinstalls even if pap is up to date",
Destination: &global.ReinstallInput,
},
},
},
{
Name: "sign",
Aliases: []string{"si", "eula", "e"},
Usage: "sign the EULA",
Action: cmd.EulaCommand,
},
{
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
Action: cli.ShowAppHelp,
},
{
Name: "version",
Aliases: []string{"v"},
Usage: "show version",
Action: func(cCtx *cli.Context) error {
cli.ShowVersion(cCtx)
return nil
},
},
{
Name: "properties",
Aliases: []string{"pr"},
Usage: "manages the server.properties file",
ArgsUsage: "[set|get] [property] [value]",
Subcommands: []*cli.Command{
{
Name: "set",
Aliases: []string{"s"},
Usage: "set property",
Action: propcmds.SetPropertyCommand,
},
{
Name: "get",
Aliases: []string{"g"},
Usage: "get property",
Action: propcmds.GetPropertyCommand,
},
{
Name: "reset",
Aliases: []string{"r"},
Usage: "downloads the default server.properties",
Action: propcmds.ResetPropertiesCommand,
},
},
},
},
}
if app.Run(os.Args) != nil {
os.Exit(1)
}
}