Skip to content

Commit

Permalink
Update to SlnEditor v4
Browse files Browse the repository at this point in the history
For the simplified interface
  • Loading branch information
timabell committed Dec 22, 2023
1 parent 9722ee9 commit ea8d16b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/CLI.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using CommandLine;
using SlnEditor;
using SlnEditor.Contracts;
using SlnEditor.Helper;
using SlnEditor.Mappings;
using SlnEditor.Models;

namespace sln_items_sync;

public class CLI(IGuidGenerator? guidGenerator = null)
{
private readonly IGuidGenerator _guidGenerator = guidGenerator ?? new DefaultGuidGenerator();
private static SolutionParser _parser = new();
private static Guid _solutionFolderTypeGuid = new ProjectTypeMapper().ToGuid(ProjectType.SolutionFolder);
private static readonly Guid SolutionFolderTypeGuid = new ProjectTypeMap().Guids[ProjectType.SolutionFolder];

public class Options
{
Expand Down Expand Up @@ -51,11 +49,10 @@ public void SyncSlnFile(string slnPath, string slnFolder, IEnumerable<string> pa
File.WriteAllText(slnPath, updatedSln);
}

// todo: allow mocking filesystem calls
// todo: move to sensible files
public string SyncSlnText(string contents, string slnFolder, IEnumerable<string> paths)
{
var solution = _parser.ParseText(contents);
var solution = new Solution(contents);

var solutionItems = FindOrCreateSolutionFolder(solution.Projects, slnFolder, slnFolder);

Expand All @@ -76,8 +73,7 @@ public string SyncSlnText(string contents, string slnFolder, IEnumerable<string>
}


var updatedSln = solution.Write();
return updatedSln;
return solution.ToString();
}

private static void SyncFile(SolutionFolder solutionItems, string path)
Expand Down Expand Up @@ -120,7 +116,7 @@ private SolutionFolder FindOrCreateSolutionFolder(ICollection<IProject> solution
}

solutionItems = new SolutionFolder(id: _guidGenerator.Next(), name: solutionFolderName, path: path,
typeGuid: _solutionFolderTypeGuid, ProjectType.SolutionFolder);
typeGuid: SolutionFolderTypeGuid, ProjectType.SolutionFolder);
solutionProjects.Add(solutionItems);

return solutionItems;
Expand Down
2 changes: 1 addition & 1 deletion src/sln-items-sync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="SlnEditor" Version="2.2.2" />
<PackageReference Include="SlnEditor" Version="4.0.0" />
</ItemGroup>
</Project>

0 comments on commit ea8d16b

Please sign in to comment.