Skip to content

Commit c1f475a

Browse files
Merge pull request #277 from tannergooding/main
Print version information on `--version`
2 parents c6bcae9 + f631c98 commit c1f475a

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

sources/ClangSharpPInvokeGenerator/Program.cs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class Program
1818
{
1919
private static RootCommand s_rootCommand;
2020
private static Option s_configOption;
21+
private static Option s_versionOption;
2122

2223
private static readonly HelpItem[] s_configOptions = new HelpItem[]
2324
{
@@ -98,19 +99,20 @@ public static async Task<int> Main(params string[] args)
9899
AddLibraryOption(s_rootCommand);
99100
AddMethodClassNameOption(s_rootCommand);
100101
AddNamespaceOption(s_rootCommand);
102+
AddOutputModeOption(s_rootCommand);
101103
AddOutputOption(s_rootCommand);
102104
AddPrefixStripOption(s_rootCommand);
103105
AddRemapOption(s_rootCommand);
104106
AddStdOption(s_rootCommand);
105107
AddTestOutputOption(s_rootCommand);
106108
AddTraverseOption(s_rootCommand);
109+
AddVersionOption(s_rootCommand);
107110
AddWithAttributeOption(s_rootCommand);
108111
AddWithCallConvOption(s_rootCommand);
109112
AddWithLibraryPathOption(s_rootCommand);
110113
AddWithSetLastErrorOption(s_rootCommand);
111114
AddWithTypeOption(s_rootCommand);
112115
AddWithUsingOption(s_rootCommand);
113-
AddOutputModeOption(s_rootCommand);
114116

115117
return await s_rootCommand.InvokeAsync(args);
116118
}
@@ -132,6 +134,7 @@ public static int Run(InvocationContext context)
132134
var methodPrefixToStrip = context.ParseResult.ValueForOption<string>("--prefixStrip");
133135
var namespaceName = context.ParseResult.ValueForOption<string>("--namespace");
134136
var outputLocation = context.ParseResult.ValueForOption<string>("--output");
137+
var outputMode = context.ParseResult.ValueForOption<PInvokeGeneratorOutputMode>("--output-mode");
135138
var remappedNameValuePairs = context.ParseResult.ValueForOption<string[]>("--remap");
136139
var std = context.ParseResult.ValueForOption<string>("--std");
137140
var testOutputLocation = context.ParseResult.ValueForOption<string>("--test-output");
@@ -142,7 +145,19 @@ public static int Run(InvocationContext context)
142145
var withSetLastErrors = context.ParseResult.ValueForOption<string[]>("--with-setlasterror");
143146
var withTypeNameValuePairs = context.ParseResult.ValueForOption<string[]>("--with-type");
144147
var withUsingNameValuePairs = context.ParseResult.ValueForOption<string[]>("--with-using");
145-
var outputMode = context.ParseResult.ValueForOption<PInvokeGeneratorOutputMode>("--output-mode");
148+
149+
var versionResult = context.ParseResult.FindResultFor(s_versionOption);
150+
151+
if (versionResult is not null)
152+
{
153+
var helpBuilder = new CustomHelpBuilder(context.Console);
154+
155+
helpBuilder.WriteLine($"{s_rootCommand.Description} version 13.0.0");
156+
helpBuilder.WriteLine($" {clang.getClangVersion()}");
157+
helpBuilder.WriteLine($" {clangsharp.getVersion()}");
158+
159+
return -1;
160+
}
146161

147162
var errorList = new List<string>();
148163

@@ -779,6 +794,19 @@ private static void AddNamespaceOption(RootCommand rootCommand)
779794
rootCommand.AddOption(option);
780795
}
781796

797+
private static void AddOutputModeOption(RootCommand rootCommand)
798+
{
799+
var option = new Option(
800+
aliases: new string[] { "--output-mode", "-om" },
801+
description: "The mode describing how the information collected from the headers are presented in the resultant bindings.",
802+
argumentType: typeof(PInvokeGeneratorOutputMode),
803+
getDefaultValue: () => PInvokeGeneratorOutputMode.CSharp,
804+
arity: ArgumentArity.ExactlyOne
805+
);
806+
807+
rootCommand.AddOption(option);
808+
}
809+
782810
private static void AddOutputOption(RootCommand rootCommand)
783811
{
784812
var option = new Option(
@@ -844,6 +872,19 @@ private static void AddTestOutputOption(RootCommand rootCommand)
844872
rootCommand.AddOption(option);
845873
}
846874

875+
private static void AddVersionOption(RootCommand rootCommand)
876+
{
877+
if (s_versionOption is null)
878+
{
879+
s_versionOption = new Option(
880+
aliases: new string[] { "--version", "-v" },
881+
description: "Prints the current version information for the tool and its native dependencies.",
882+
arity: ArgumentArity.Zero
883+
);
884+
}
885+
rootCommand.AddOption(s_versionOption);
886+
}
887+
847888
private static void AddTraverseOption(RootCommand rootCommand)
848889
{
849890
var option = new Option(
@@ -934,18 +975,5 @@ private static void AddWithUsingOption(RootCommand rootCommand)
934975

935976
rootCommand.AddOption(option);
936977
}
937-
938-
private static void AddOutputModeOption(RootCommand rootCommand)
939-
{
940-
var option = new Option(
941-
aliases: new string[] { "--output-mode", "-om" },
942-
description: "The mode describing how the information collected from the headers are presented in the resultant bindings.",
943-
argumentType: typeof(PInvokeGeneratorOutputMode),
944-
getDefaultValue: () => PInvokeGeneratorOutputMode.CSharp,
945-
arity: ArgumentArity.ExactlyOne
946-
);
947-
948-
rootCommand.AddOption(option);
949-
}
950978
}
951979
}

0 commit comments

Comments
 (0)