Browse Source

General CLI code cleanups.

pull/1865/head
Joao Matos 10 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 @@ -152,7 +152,9 @@ namespace CppSharp
{
bool searchQuery = args.IndexOf('*') >= 0 || args.IndexOf('?') >= 0;
if (searchQuery || Directory.Exists(args))
{
GetFilesFromPath(args, errorMessages);
}
else if (File.Exists(args))
options.HeaderFiles.Add(args);
else
@ -175,7 +177,8 @@ namespace CppSharp @@ -175,7 +177,8 @@ namespace CppSharp
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);
path = path.Substring(0, lastSeparatorPosition);
@ -257,7 +260,8 @@ namespace CppSharp @@ -257,7 +260,8 @@ namespace CppSharp
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)
@ -275,7 +279,8 @@ namespace CppSharp @@ -275,7 +279,8 @@ namespace CppSharp
{
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;
}

31
src/CLI/Generator.cs

@ -91,22 +91,11 @@ namespace CppSharp @@ -91,22 +91,11 @@ namespace CppSharp
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))
options.OutputFileName = moduleName;
options.OutputFileName = GetModuleNameFromHeaderFiles();
if (string.IsNullOrEmpty(options.OutputNamespace))
options.OutputNamespace = moduleName;
options.OutputNamespace = GetModuleNameFromHeaderFiles();
if (options.IncludeDirs.Count == 0)
options.IncludeDirs.Add(Path.GetDirectoryName(options.HeaderFiles.First()));
@ -114,6 +103,22 @@ namespace CppSharp @@ -114,6 +103,22 @@ namespace CppSharp
SetupTargetTriple();
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)

Loading…
Cancel
Save