Skip to content

Document ability to use wildcards for with-access-specifier #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
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
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,23 @@ Options:
-to, --test-output <test-output> The output location to write the generated tests to. []
-t, --traverse <traverse> A file name included either directly or indirectly by -f that should be traversed during binding generation. []
-v, --version <version> Prints the current version information for the tool and its native dependencies.
-was, --with-access-specifier <with-access-specifier> An access specifier to be used with the given qualified or remapped declaration name during binding generation. []
-wa, --with-attribute <with-attribute> An attribute to be added to the given remapped declaration name during binding generation. []
-wcc, --with-callconv <with-callconv> A calling convention to be used for the given declaration during binding generation. []
-wc, --with-class <with-class> A class to be used for the given remapped constant or function declaration name during binding generation. []
-wg, --with-guid <with-guid> A GUID to be used for the given declaration during binding generation. []
-wlb, --with-librarypath <with-librarypath> A library path to be used for the given declaration during binding generation. []
-wmi, --with-manual-import <with-manual-import> A remapped function name to be treated as a manual import during binding generation. []
-wn, --with-namespace <with-namespace> A namespace to be used for the given remapped declaration name during binding generation. []
-wsle, --with-setlasterror <with-setlasterror> Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. []
-wsgct, --with-suppressgctransition <with-suppressgctransition> Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. []
-wts, --with-transparent-struct <with-transparent-struct> A remapped type name to be treated as a transparent wrapper during binding generation. []
-wt, --with-type <with-type> A type to be used for the given enum declaration during binding generation. []
-wu, --with-using <with-using> A using directive to be included for the given remapped declaration name during binding generation. []
-was, --with-access-specifier <with-access-specifier> An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards. []
-wa, --with-attribute <with-attribute> An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards. []
-wcc, --with-callconv <with-callconv> A calling convention to be used for the given declaration during binding generation. Supports wildcards. []
-wc, --with-class <with-class> A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards. []
-wg, --with-guid <with-guid> A GUID to be used for the given declaration during binding generation. Supports wildcards. []
-wlb, --with-librarypath <with-librarypath> A library path to be used for the given declaration during binding generation. Supports wildcards. []
-wmi, --with-manual-import <with-manual-import> A remapped function name to be treated as a manual import during binding generation. Supports wildcards. []
-wn, --with-namespace <with-namespace> A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards. []
-wsle, --with-setlasterror <with-setlasterror> Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards. []
-wsgct, --with-suppressgctransition <with-suppressgctransition> Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards. []
-wts, --with-transparent-struct <with-transparent-struct> A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards. []
-wt, --with-type <with-type> A type to be used for the given enum declaration during binding generation. Supports wildcards. []
-wu, --with-using <with-using> A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards. []
-?, -h, --help Show help and usage information

Wildcards:
You can use * as catch-all rule for remapping procedures. For example if you want make all of your generated code internal you can use --with-access-specifier *=Internal.
```

The available configuration options (visible with `-c help`) are:
Expand Down
2 changes: 1 addition & 1 deletion sources/ClangSharpPInvokeGenerator/CustomHelpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public void Write(params TwoColumnHelpRow[] helpItems)
}

public void WriteLine() => Console.Out.WriteLine();

public void WriteLine(string value) => Console.Out.WriteLine(value);
}
43 changes: 28 additions & 15 deletions sources/ClangSharpPInvokeGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,23 @@ static Program()
Handler.SetHandler(s_rootCommand, (Action<InvocationContext>)Run);
}

public static IEnumerable<HelpSectionDelegate> GetExtendedHelp(HelpContext context)
{
foreach (var sectionDelegate in HelpBuilder.Default.GetLayout())
yield return sectionDelegate;

yield return _ =>
{
Console.WriteLine(
@"Wildcards:
You can use * as catch-all rule for remapping procedures. For example if you want make all of your generated code internal you can use --with-access-specifier *=Internal.");
};
}

public static async Task<int> Main(params string[] args)
{
var parser = new CommandLineBuilder(s_rootCommand)
.UseHelp()
.UseHelp(context => context.HelpBuilder.CustomizeLayout(GetExtendedHelp))
.UseEnvironmentVariableDirective()
.UseParseDirective()
.UseSuggestDirective()
Expand Down Expand Up @@ -1156,7 +1169,7 @@ private static Option<string[]> GetWithAccessSpecifierOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-access-specifier", "-was" },
description: "An access specifier to be used with the given qualified or remapped declaration name during binding generation.",
description: "An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1167,7 +1180,7 @@ private static Option<string[]> GetWithAttributeOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-attribute", "-wa" },
description: "An attribute to be added to the given remapped declaration name during binding generation.",
description: "An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1178,7 +1191,7 @@ private static Option<string[]> GetWithCallConvOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-callconv", "-wcc" },
description: "A calling convention to be used for the given declaration during binding generation.",
description: "A calling convention to be used for the given declaration during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1189,7 +1202,7 @@ private static Option<string[]> GetWithClassOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-class", "-wc" },
description: "A class to be used for the given remapped constant or function declaration name during binding generation.",
description: "A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1200,7 +1213,7 @@ private static Option<string[]> GetWithGuidOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-guid", "-wg" },
description: "A GUID to be used for the given declaration during binding generation.",
description: "A GUID to be used for the given declaration during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1211,7 +1224,7 @@ private static Option<string[]> GetWithLibraryPathOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-librarypath", "-wlb" },
description: "A library path to be used for the given declaration during binding generation.",
description: "A library path to be used for the given declaration during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1222,7 +1235,7 @@ private static Option<string[]> GetWithManualImportOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-manual-import", "-wmi" },
description: "A remapped function name to be treated as a manual import during binding generation.",
description: "A remapped function name to be treated as a manual import during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1233,7 +1246,7 @@ private static Option<string[]> GetWithNamespaceOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-namespace", "-wn" },
description: "A namespace to be used for the given remapped declaration name during binding generation.",
description: "A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1244,7 +1257,7 @@ private static Option<string[]> GetWithSetLastErrorOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-setlasterror", "-wsle" },
description: "Add the SetLastError=true modifier or SetsSystemLastError attribute to a given DllImport or UnmanagedFunctionPointer.",
description: "Add the SetLastError=true modifier or SetsSystemLastError attribute to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1255,7 +1268,7 @@ private static Option<string[]> GetWithSuppressGCTransitionOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-suppressgctransition", "-wsgct" },
description: "Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer.",
description: "Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1266,7 +1279,7 @@ private static Option<string[]> GetWithTransparentStructOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-transparent-struct", "-wts" },
description: "A remapped type name to be treated as a transparent wrapper during binding generation.",
description: "A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1277,7 +1290,7 @@ private static Option<string[]> GetWithTypeOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-type", "-wt" },
description: "A type to be used for the given enum declaration during binding generation.",
description: "A type to be used for the given enum declaration during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1288,7 +1301,7 @@ private static Option<string[]> GetWithUsingOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-using", "-wu" },
description: "A using directive to be included for the given remapped declaration name during binding generation.",
description: "A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand All @@ -1299,7 +1312,7 @@ private static Option<string[]> GetWithPackingOption()
{
return new Option<string[]>(
aliases: new string[] { "--with-packing", "-wp" },
description: "Overrides the StructLayoutAttribute.Pack property for the given type.",
description: "Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.",
getDefaultValue: Array.Empty<string>
) {
AllowMultipleArgumentsPerToken = true
Expand Down