Skip to content

Commit

Permalink
Option to convert files excluding subdirectories (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya authored Aug 25, 2024
1 parent 09e695d commit b84f9de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions JavaToCSharp/JavaConversionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class JavaConversionOptions

public IList<string> StaticUsingEnumNames { get; } = new List<string>();

public bool IncludeSubdirectories { get; set; } = true;

public bool IncludeUsings { get; set; } = true;

public bool IncludeNamespace { get; set; } = true;
Expand Down
10 changes: 9 additions & 1 deletion JavaToCSharpCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class Program
private static readonly ILoggerFactory _loggerFactory;
private static readonly ILogger _logger;

private static readonly Option<bool> _includeSubdirectoriesOption = new(
name: "--include-subdirectories",
description: "When the command is dir, converts files in all subdirectories",
getDefaultValue: () => true);

private static readonly Option<bool> _includeUsingsOption = new(
name: "--include-usings",
description: "Include using directives in output",
Expand Down Expand Up @@ -82,6 +87,7 @@ public static async Task Main(string[] args)
rootCommand.AddCommand(CreateFileCommand());
rootCommand.AddCommand(CreateDirectoryCommand());

rootCommand.AddGlobalOption(_includeSubdirectoriesOption);
rootCommand.AddGlobalOption(_includeUsingsOption);
rootCommand.AddGlobalOption(_includeNamespaceOption);
rootCommand.AddGlobalOption(_includeCommentsOption);
Expand Down Expand Up @@ -131,6 +137,7 @@ private static JavaConversionOptions GetJavaConversionOptions(InvocationContext
{
var options = new JavaConversionOptions
{
IncludeSubdirectories = context.ParseResult.GetValueForOption(_includeSubdirectoriesOption),
IncludeUsings = context.ParseResult.GetValueForOption(_includeUsingsOption),
IncludeComments = context.ParseResult.GetValueForOption(_includeCommentsOption),
IncludeNamespace = context.ParseResult.GetValueForOption(_includeNamespaceOption),
Expand Down Expand Up @@ -193,7 +200,8 @@ private static void ConvertToCSharpDir(DirectoryInfo inputDirectory, DirectoryIn
{
if (inputDirectory.Exists)
{
foreach (var f in inputDirectory.GetFiles("*.java", SearchOption.AllDirectories))
var searchOption = options.IncludeSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
foreach (var f in inputDirectory.GetFiles("*.java", searchOption))
{
string? directoryName = f.DirectoryName;
if (string.IsNullOrWhiteSpace(directoryName))
Expand Down

0 comments on commit b84f9de

Please sign in to comment.