-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from enisn/find-file
Add finding specific files command
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters