-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lfs): Support building directory structure representation (#15)
- Loading branch information
Showing
13 changed files
with
593 additions
and
47 deletions.
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
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
53 changes: 53 additions & 0 deletions
53
src/FlowPair/LocalFileSystem/GetDirectoryStructure/GetDirectoryStructureHandler.cs
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,53 @@ | ||
using System.Collections.Frozen; | ||
using System.Globalization; | ||
using System.IO.Abstractions; | ||
using System.Text; | ||
using AutomaticInterface; | ||
|
||
namespace Ciandt.FlowTools.FlowPair.LocalFileSystem.GetDirectoryStructure; | ||
|
||
public partial interface IGetDirectoryStructureHandler; | ||
|
||
[GenerateAutomaticInterface] | ||
public sealed class GetDirectoryStructureHandler | ||
: IGetDirectoryStructureHandler | ||
{ | ||
private static readonly FrozenSet<string> s_ignoreList = | ||
[ | ||
"__pycache__", "artifacts", "bin", "blib", "build", "cache", "dist", "node_modules", "obj", "out", "pkg", | ||
"Pods", "project", "publish", "target", "vendor", "venv", "xcuserdata" | ||
]; | ||
|
||
public string Execute(IDirectoryInfo directoryInfo) | ||
{ | ||
var result = new StringBuilder(); | ||
FillDirectories(result, directoryInfo, 0); | ||
return result.ToString(); | ||
} | ||
|
||
private static void FillDirectories(StringBuilder builder, IDirectoryInfo directoryInfo, int level) | ||
{ | ||
PrintLevel(builder, level); | ||
builder.Append(CultureInfo.InvariantCulture, $"{directoryInfo.Name}/"); | ||
|
||
foreach (var item in directoryInfo.EnumerateDirectories().Where(IsUserDirectory)) | ||
{ | ||
FillDirectories(builder, item, level + 1); | ||
} | ||
} | ||
|
||
private static bool IsUserDirectory(IDirectoryInfo x) | ||
{ | ||
return !x.Name.StartsWith('.') && !s_ignoreList.Contains(x.Name); | ||
} | ||
|
||
private static void PrintLevel(StringBuilder builder, int level) | ||
{ | ||
if (level == 0) | ||
return; | ||
|
||
builder.AppendLine(); | ||
builder.Append(string.Join(null, Enumerable.Repeat("| ", level - 1))); | ||
builder.Append("|-- "); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/FlowPair/LocalFileSystem/Infrastructure/ILocalFileSystemModule.cs
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,10 @@ | ||
using Ciandt.FlowTools.FlowPair.LocalFileSystem.GetDirectoryStructure; | ||
using Ciandt.FlowTools.FlowPair.LocalFileSystem.Services; | ||
using Jab; | ||
|
||
namespace Ciandt.FlowTools.FlowPair.LocalFileSystem.Infrastructure; | ||
|
||
[ServiceProviderModule] | ||
[Singleton(typeof(IWorkingDirectoryWalker), typeof(WorkingDirectoryWalker))] | ||
[Singleton(typeof(IGetDirectoryStructureHandler), typeof(GetDirectoryStructureHandler))] | ||
public interface ILocalFileSystemModule; |
35 changes: 35 additions & 0 deletions
35
src/FlowPair/LocalFileSystem/Services/WorkingDirectoryWalker.cs
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,35 @@ | ||
using System.IO.Abstractions; | ||
using AutomaticInterface; | ||
|
||
namespace Ciandt.FlowTools.FlowPair.LocalFileSystem.Services; | ||
|
||
public partial interface IWorkingDirectoryWalker; | ||
|
||
[GenerateAutomaticInterface] | ||
public sealed class WorkingDirectoryWalker( | ||
IFileSystem fileSystem) | ||
: IWorkingDirectoryWalker | ||
{ | ||
public Option<IDirectoryInfo> TryFindRepositoryRoot(string? path) | ||
{ | ||
var currentDirectory = fileSystem.DirectoryInfo.New(path ?? fileSystem.Directory.GetCurrentDirectory()); | ||
if (!currentDirectory.Exists) | ||
{ | ||
return None; | ||
} | ||
|
||
while (currentDirectory != null) | ||
{ | ||
if (currentDirectory | ||
.EnumerateDirectories(".git", SearchOption.TopDirectoryOnly) | ||
.Any()) | ||
{ | ||
return Some(currentDirectory); | ||
} | ||
|
||
currentDirectory = currentDirectory.Parent; | ||
} | ||
|
||
return None; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\FlowPair\FlowPair.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" /> | ||
<PackageReference Include="coverlet.msbuild"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" /> | ||
<PackageReference Include="coverlet.msbuild"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" /> | ||
<PackageReference Include="FxKit.Testing" /> | ||
<PackageReference Include="JetBrains.Annotations" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.