Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions sources/ClangSharpPInvokeGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Program
{
private static RootCommand s_rootCommand;
private static Option s_configOption;
private static Option s_versionOption;

private static readonly HelpItem[] s_configOptions = new HelpItem[]
{
Expand Down Expand Up @@ -98,19 +99,20 @@ public static async Task<int> Main(params string[] args)
AddLibraryOption(s_rootCommand);
AddMethodClassNameOption(s_rootCommand);
AddNamespaceOption(s_rootCommand);
AddOutputModeOption(s_rootCommand);
AddOutputOption(s_rootCommand);
AddPrefixStripOption(s_rootCommand);
AddRemapOption(s_rootCommand);
AddStdOption(s_rootCommand);
AddTestOutputOption(s_rootCommand);
AddTraverseOption(s_rootCommand);
AddVersionOption(s_rootCommand);
AddWithAttributeOption(s_rootCommand);
AddWithCallConvOption(s_rootCommand);
AddWithLibraryPathOption(s_rootCommand);
AddWithSetLastErrorOption(s_rootCommand);
AddWithTypeOption(s_rootCommand);
AddWithUsingOption(s_rootCommand);
AddOutputModeOption(s_rootCommand);

return await s_rootCommand.InvokeAsync(args);
}
Expand All @@ -132,6 +134,7 @@ public static int Run(InvocationContext context)
var methodPrefixToStrip = context.ParseResult.ValueForOption<string>("--prefixStrip");
var namespaceName = context.ParseResult.ValueForOption<string>("--namespace");
var outputLocation = context.ParseResult.ValueForOption<string>("--output");
var outputMode = context.ParseResult.ValueForOption<PInvokeGeneratorOutputMode>("--output-mode");
var remappedNameValuePairs = context.ParseResult.ValueForOption<string[]>("--remap");
var std = context.ParseResult.ValueForOption<string>("--std");
var testOutputLocation = context.ParseResult.ValueForOption<string>("--test-output");
Expand All @@ -142,7 +145,19 @@ public static int Run(InvocationContext context)
var withSetLastErrors = context.ParseResult.ValueForOption<string[]>("--with-setlasterror");
var withTypeNameValuePairs = context.ParseResult.ValueForOption<string[]>("--with-type");
var withUsingNameValuePairs = context.ParseResult.ValueForOption<string[]>("--with-using");
var outputMode = context.ParseResult.ValueForOption<PInvokeGeneratorOutputMode>("--output-mode");

var versionResult = context.ParseResult.FindResultFor(s_versionOption);

if (versionResult is not null)
{
var helpBuilder = new CustomHelpBuilder(context.Console);

helpBuilder.WriteLine($"{s_rootCommand.Description} version 13.0.0");
helpBuilder.WriteLine($" {clang.getClangVersion()}");
helpBuilder.WriteLine($" {clangsharp.getVersion()}");

return -1;
}

var errorList = new List<string>();

Expand Down Expand Up @@ -779,6 +794,19 @@ private static void AddNamespaceOption(RootCommand rootCommand)
rootCommand.AddOption(option);
}

private static void AddOutputModeOption(RootCommand rootCommand)
{
var option = new Option(
aliases: new string[] { "--output-mode", "-om" },
description: "The mode describing how the information collected from the headers are presented in the resultant bindings.",
argumentType: typeof(PInvokeGeneratorOutputMode),
getDefaultValue: () => PInvokeGeneratorOutputMode.CSharp,
arity: ArgumentArity.ExactlyOne
);

rootCommand.AddOption(option);
}

private static void AddOutputOption(RootCommand rootCommand)
{
var option = new Option(
Expand Down Expand Up @@ -844,6 +872,19 @@ private static void AddTestOutputOption(RootCommand rootCommand)
rootCommand.AddOption(option);
}

private static void AddVersionOption(RootCommand rootCommand)
{
if (s_versionOption is null)
{
s_versionOption = new Option(
aliases: new string[] { "--version", "-v" },
description: "Prints the current version information for the tool and its native dependencies.",
arity: ArgumentArity.Zero
);
}
rootCommand.AddOption(s_versionOption);
}

private static void AddTraverseOption(RootCommand rootCommand)
{
var option = new Option(
Expand Down Expand Up @@ -934,18 +975,5 @@ private static void AddWithUsingOption(RootCommand rootCommand)

rootCommand.AddOption(option);
}

private static void AddOutputModeOption(RootCommand rootCommand)
{
var option = new Option(
aliases: new string[] { "--output-mode", "-om" },
description: "The mode describing how the information collected from the headers are presented in the resultant bindings.",
argumentType: typeof(PInvokeGeneratorOutputMode),
getDefaultValue: () => PInvokeGeneratorOutputMode.CSharp,
arity: ArgumentArity.ExactlyOne
);

rootCommand.AddOption(option);
}
}
}