Browse Source

General CLI code cleanups.

pull/1865/head
Joao Matos 11 months ago
parent
commit
aaaffff727
  1. 11
      src/CLI/CLI.cs
  2. 31
      src/CLI/Generator.cs

11
src/CLI/CLI.cs

@ -152,7 +152,9 @@ namespace CppSharp
{ {
bool searchQuery = args.IndexOf('*') >= 0 || args.IndexOf('?') >= 0; bool searchQuery = args.IndexOf('*') >= 0 || args.IndexOf('?') >= 0;
if (searchQuery || Directory.Exists(args)) if (searchQuery || Directory.Exists(args))
{
GetFilesFromPath(args, errorMessages); GetFilesFromPath(args, errorMessages);
}
else if (File.Exists(args)) else if (File.Exists(args))
options.HeaderFiles.Add(args); options.HeaderFiles.Add(args);
else else
@ -175,7 +177,8 @@ namespace CppSharp
if (lastSeparatorPosition >= 0) if (lastSeparatorPosition >= 0)
{ {
if (path.IndexOf('*', lastSeparatorPosition) >= lastSeparatorPosition || path.IndexOf('?', lastSeparatorPosition) >= lastSeparatorPosition) if (path.IndexOf('*', lastSeparatorPosition) >= lastSeparatorPosition ||
path.IndexOf('?', lastSeparatorPosition) >= lastSeparatorPosition)
{ {
searchPattern = path.Substring(lastSeparatorPosition + 1); searchPattern = path.Substring(lastSeparatorPosition + 1);
path = path.Substring(0, lastSeparatorPosition); path = path.Substring(0, lastSeparatorPosition);
@ -257,7 +260,8 @@ namespace CppSharp
return; return;
} }
errorMessages.Add($"Unknown target architecture: {architecture}. Defaulting to {options.Architecture}"); errorMessages.Add($@"Unknown target architecture: {architecture}. \
Defaulting to {options.Architecture}");
} }
static void PrintErrorMessages(List<string> errorMessages) static void PrintErrorMessages(List<string> errorMessages)
@ -275,7 +279,8 @@ namespace CppSharp
{ {
PrintErrorMessages(errorMessages); PrintErrorMessages(errorMessages);
// Don't need to show the help since if ParseCommandLineArgs returns false the help has already been shown // Don't need to show the help since if ParseCommandLineArgs returns false
// since the help has already been shown
return; return;
} }

31
src/CLI/Generator.cs

@ -91,22 +91,11 @@ namespace CppSharp
options.OutputDir = Path.Combine(Directory.GetCurrentDirectory(), "gen"); options.OutputDir = Path.Combine(Directory.GetCurrentDirectory(), "gen");
} }
string moduleName;
if (options.HeaderFiles.Count == 1)
{
moduleName = Path.GetFileNameWithoutExtension(options.HeaderFiles.First());
}
else
{
var dir = Path.GetDirectoryName(options.HeaderFiles.First());
moduleName = new DirectoryInfo(dir).Name;
}
if (string.IsNullOrEmpty(options.OutputFileName)) if (string.IsNullOrEmpty(options.OutputFileName))
options.OutputFileName = moduleName; options.OutputFileName = GetModuleNameFromHeaderFiles();
if (string.IsNullOrEmpty(options.OutputNamespace)) if (string.IsNullOrEmpty(options.OutputNamespace))
options.OutputNamespace = moduleName; options.OutputNamespace = GetModuleNameFromHeaderFiles();
if (options.IncludeDirs.Count == 0) if (options.IncludeDirs.Count == 0)
options.IncludeDirs.Add(Path.GetDirectoryName(options.HeaderFiles.First())); options.IncludeDirs.Add(Path.GetDirectoryName(options.HeaderFiles.First()));
@ -114,6 +103,22 @@ namespace CppSharp
SetupTargetTriple(); SetupTargetTriple();
return true; return true;
string GetModuleNameFromHeaderFiles()
{
string moduleName;
if (options.HeaderFiles.Count == 1)
{
moduleName = Path.GetFileNameWithoutExtension(options.HeaderFiles.First());
}
else
{
var dir = Path.GetDirectoryName(options.HeaderFiles.First());
moduleName = new DirectoryInfo(dir).Name;
}
return moduleName;
}
} }
public void Setup(Driver driver) public void Setup(Driver driver)

Loading…
Cancel
Save