in lang/csharp/src/apache/codegen/AvroGen.cs [27:144]
public static int Main(string[] args)
{
// Print usage if no arguments provided
if (args.Length == 0)
{
Usage();
return 1;
}
// Print usage if help requested
if (args.Contains("-h") || args.Contains("--help"))
{
Usage();
return 0;
}
if (args.Contains("--version") || args.Contains("-V"))
{
// Print version information
// Note: Use InformationalVersion attribute
// It is capable to include semver prerelease information label (if prerelease), e.g. 1.x.y-beta.z
Console.WriteLine(typeof(AvroGenTool).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
return 0;
}
// Parse command line arguments
bool? isProtocol = null;
string inputFile = null;
string outputDir = null;
bool skipDirectoriesCreation = false;
var namespaceMapping = new Dictionary<string, string>();
for (int i = 0; i < args.Length; ++i)
{
if (args[i] == "-p")
{
if (i + 1 >= args.Length)
{
Console.Error.WriteLine("Missing path to protocol file");
Usage();
return 1;
}
isProtocol = true;
inputFile = args[++i];
}
else if (args[i] == "-s")
{
if (i + 1 >= args.Length)
{
Console.Error.WriteLine("Missing path to schema file");
Usage();
return 1;
}
isProtocol = false;
inputFile = args[++i];
}
else if (args[i] == "--namespace")
{
if (i + 1 >= args.Length)
{
Console.Error.WriteLine("Missing namespace mapping");
Usage();
return 1;
}
var parts = args[++i].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 2)
{
Console.Error.WriteLine("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
Usage();
return 1;
}
namespaceMapping[parts[0]] = parts[1];
}
else if (args[i] == "--skip-directories")
{
skipDirectoriesCreation = true;
}
else if (outputDir == null)
{
outputDir = args[i];
}
else
{
Console.Error.WriteLine("Unexpected command line argument: {0}", args[i]);
Usage();
}
}
// Ensure we got all the command line arguments we need
bool isValid = true;
int rc = 0;
if (!isProtocol.HasValue || inputFile == null)
{
Console.Error.WriteLine("Must provide either '-p <protocolfile>' or '-s <schemafile>'");
isValid = false;
}
else if (outputDir == null)
{
Console.Error.WriteLine("Must provide 'outputdir'");
isValid = false;
}
if (!isValid)
{
Usage();
rc = 1;
}
else if (isProtocol.Value)
rc = GenProtocol(inputFile, outputDir, namespaceMapping);
else
rc = GenSchema(inputFile, outputDir, namespaceMapping, skipDirectoriesCreation);
return rc;
}