forked from DeltaV-Station/Delta-v
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandLineArguments.cs
116 lines (98 loc) · 3.41 KB
/
CommandLineArguments.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.MapRenderer.Extensions;
namespace Content.MapRenderer;
public sealed class CommandLineArguments
{
public List<string> Maps { get; set; } = new();
public OutputFormat Format { get; set; } = OutputFormat.png;
public bool ExportViewerJson { get; set; } = false;
public string OutputPath { get; set; } = DirectoryExtensions.MapImages().FullName;
public bool ArgumentsAreFileNames { get; set; } = false;
public static bool TryParse(IReadOnlyList<string> args, [NotNullWhen(true)] out CommandLineArguments? parsed)
{
parsed = new CommandLineArguments();
if (args.Count == 0)
{
PrintHelp();
//Returns true here so the user can select what maps they want to render
return true;
}
using var enumerator = args.GetEnumerator();
while (enumerator.MoveNext())
{
var argument = enumerator.Current;
switch (argument)
{
case "--format":
enumerator.MoveNext();
if (!Enum.TryParse<OutputFormat>(enumerator.Current, out var format))
{
Console.WriteLine("Invalid format specified for option: {0}", argument);
parsed = null;
return false;
}
parsed.Format = format;
break;
case "--viewer":
parsed.ExportViewerJson = true;
break;
case "-o":
case "--output":
enumerator.MoveNext();
parsed.OutputPath = enumerator.Current;
break;
case "-f":
case "--files":
parsed.ArgumentsAreFileNames = true;
break;
case "-h":
case "--help":
PrintHelp();
return false;
default:
parsed.Maps.Add(argument);
break;
}
}
if (parsed.ArgumentsAreFileNames && parsed.Maps.Count == 0)
{
Console.WriteLine("No file names specified!");
PrintHelp();
return false;
}
return true;
}
public static void PrintHelp()
{
Console.WriteLine(@"Content.MapRenderer <options> [map names]
Options:
--format <png|webp>
Specifies the format the map images will be exported as.
Defaults to: png
--viewer
Causes the map renderer to create the map.json files required for use with the map viewer.
Also puts the maps in the required directory structure.
-o / --output <output path>
Changes the path the rendered maps will get saved to.
Defaults to Resources/MapImages
-f / --files
This option tells the map renderer that you supplied a list of map file names instead of their ids.
Example: Content.MapRenderer -f box.yml bagel.yml
-h / --help
Displays this help text");
}
}
public sealed class CommandLineArgumentException : Exception
{
public CommandLineArgumentException(string? message) : base(message)
{
}
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum OutputFormat
{
png,
webp
}