Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add finding specific files command #16

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading