forked from OpenKH/OpenKh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
70 lines (63 loc) · 2.15 KB
/
Program.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
using McMaster.Extensions.CommandLineUtils;
using Newtonsoft.Json.Serialization;
using NJsonSchema;
using NJsonSchema.Generation;
using OpenKh.Command.MapGen.Models;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace OpenKh.Command.MapGenUtils
{
[Command("OpenKh.Command.MapGenUtils")]
[VersionOptionFromMember("--version", MemberName = nameof(GetVersion))]
[Subcommand(typeof(GenSchemaCommand))]
internal class Program
{
static int Main(string[] args)
{
try
{
return CommandLineApplication.Execute<Program>(args);
}
catch (FileNotFoundException e)
{
Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit.");
return 1;
}
catch (Exception e)
{
Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}");
return 1;
}
}
protected int OnExecute(CommandLineApplication app)
{
app.ShowHelp();
return 1;
}
private static string GetVersion()
=> typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "";
[HelpOption]
[Command(Description = "Generate schema for mapdef.yml")]
private class GenSchemaCommand
{
[Required]
[DirectoryExists]
[Argument(0, Description = "Output dir")]
public string? OutDir { get; set; }
protected int OnExecute(CommandLineApplication app)
{
var schema = JsonSchema.FromType<MapGenConfig>(
new JsonSchemaGeneratorSettings
{
}
);
var schemaData = schema.ToJson();
File.WriteAllText(
Path.Combine(OutDir ?? ".", "mapdef.schema.json"),
schemaData
);
return 0;
}
}
}
}