Skip to content

Commit

Permalink
Merge pull request #16 from enisn/find-file
Browse files Browse the repository at this point in the history
Add finding specific files command
  • Loading branch information
enisn authored Aug 21, 2024
2 parents e3a5e01 + a668de4 commit cf3bc77
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AbpDevTools/AbpDevTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.4.3</Version>
<Version>1.4.4</Version>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackageIcon>logo_128.png</PackageIcon>
Expand Down
48 changes: 48 additions & 0 deletions src/AbpDevTools/Commands/FindFileCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using CliFx.Infrastructure;

namespace AbpDevTools.Commands;

[Command("find-file", Description = "Finds the specified text in the solution.")]
public class FindFileCommand : ICommand
{
protected FileExplorer FileExplorer { get; }

[CommandOption("ascendant", 'a', Description = "Determined searching direction as 'Ascendant' or 'Descendants'.")]
public bool Ascendant { get; set; } = false;

[CommandParameter(0, Description = "Text to search.")]
public string SearchTerm { get; set; } = string.Empty;

[CommandParameter(1, Description = "Directory to search", IsRequired = false)]
public string WorkingDirectory { get; set; } = string.Empty;

public FindFileCommand(FileExplorer fileExplorer)
{
FileExplorer = fileExplorer;
}

public async ValueTask ExecuteAsync(IConsole console)
{
if (string.IsNullOrWhiteSpace(WorkingDirectory))
{
WorkingDirectory = Directory.GetCurrentDirectory();
}

foreach (var file in Find())
{
await console.Output.WriteLineAsync(file);
}
}

IEnumerable<string> Find()
{
if (Ascendant)
{
return FileExplorer.FindAscendants(WorkingDirectory, SearchTerm);
}
else
{
return FileExplorer.FindDescendants(WorkingDirectory, SearchTerm);
}
}
}
1 change: 1 addition & 0 deletions src/AbpDevTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static CliApplicationBuilder BuildServices(this CliApplicationBuilder bui
typeof(CleanCommand),
typeof(DatabaseDropCommand),
typeof(SwitchToEnvironmentCommand),
typeof(FindFileCommand),
};

foreach (var commandType in commands)
Expand Down

0 comments on commit cf3bc77

Please sign in to comment.