From aaaffff727f2f187c101c54067779f0842ed05e6 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Tue, 3 Sep 2024 16:15:16 +0100 Subject: [PATCH] General CLI code cleanups. --- src/CLI/CLI.cs | 11 ++++++++--- src/CLI/Generator.cs | 31 ++++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/CLI/CLI.cs b/src/CLI/CLI.cs index 7b8068a4..e2363bd6 100644 --- a/src/CLI/CLI.cs +++ b/src/CLI/CLI.cs @@ -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 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 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 errorMessages) @@ -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; } diff --git a/src/CLI/Generator.cs b/src/CLI/Generator.cs index e7ac5d59..4da7c538 100644 --- a/src/CLI/Generator.cs +++ b/src/CLI/Generator.cs @@ -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 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)