namespace Bts.DataStreamPublisher;
using CommandLine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
public class DataStreamPublisherConfig {
///
/// The tables to publish on startup. Each key/value represents a table name/query to publish.
///
public List? PublisherNodes { get; set; }
public List? CsvDirs { get; set; }
[Option(
"config",
MetaValue = "PATH",
HelpText = "Path to json file representing these options (DataStreamPublisherConfig)")]
[JsonIgnore]
public string? ConfigFile { get; set; }
public static DataStreamPublisherConfig Default() =>
new() { };
public void MergeWith(DataStreamPublisherConfig other) {
PublisherNodes ??= other.PublisherNodes;
ConfigFile ??= other.ConfigFile;
}
///
/// Merges options with those defined in `ConfigFile` (does not overwrite
/// non-null existing values).
///
///
/// JsonSerializer.Deserialize returns null
///
public void MergeWithConfigFile() {
if (ConfigFile is null) {
return;
}
var cfgString = File.ReadAllText(ConfigFile);
var parsedCfg = JsonSerializer.Deserialize(cfgString) ??
throw new InvalidOperationException($"Failed to parse json from {ConfigFile}");
MergeWith(parsedCfg);
ConfigFile = null;
}
}