-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (58 loc) · 2.14 KB
/
Program.cs
File metadata and controls
64 lines (58 loc) · 2.14 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using zobo.Configuration.Input;
using zobo.Configuration.Output;
namespace zobo
{
class Program
{
static void Main(string[] args)
{
var contractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy
{
OverrideSpecifiedNames = false
}
};
var converters = new List<JsonConverter> { new StringEnumConverter(), new TargetDefinitionConverter() };
var jsonSettings = new JsonSerializerSettings
{
ContractResolver = contractResolver,
Converters = converters
};
Parser.Default.ParseArguments<CLIOptions>(args)
.WithParsed<CLIOptions>(options =>
{
var input = new StreamReader(options.ZoneFile);
string jsonString;
if (options.ZoneFile.EndsWith(".yaml") || options.ZoneFile.EndsWith(".yml"))
{
jsonString = ToJson(input.ReadToEnd());
}
else
{
jsonString = input.ReadToEnd();
}
var zoneConfig = JsonConvert.DeserializeObject<ZoneConfig>(jsonString, jsonSettings);
var vyosConfig = new VyosConfiguration(zoneConfig, options);
vyosConfig.PrintRules();
});
}
private static string ToJson(string yaml)
{
dynamic yamlObject = new DeserializerBuilder()
.WithNamingConvention(new UnderscoredNamingConvention())
.Build()
.Deserialize<dynamic>(yaml);
return JsonConvert.SerializeObject(yamlObject);
}
}
}