Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,4 @@ ASALocalRun/
.nuke

.DS_Store
.tokensave
110 changes: 94 additions & 16 deletions macSynkker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,53 +75,131 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{1A70000D
build.cmd = build.cmd
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.MacOS.HomeBrew.Tests", "tests\CreativeCoders.MacOS.HomeBrew.Tests\CreativeCoders.MacOS.HomeBrew.Tests.csproj", "{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C033DF64-285B-4C44-AFFC-400878C92C73} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{1C050676-278A-4DD4-8396-A27BA85A89E6} = {C033DF64-285B-4C44-AFFC-400878C92C73}
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8} = {1C050676-278A-4DD4-8396-A27BA85A89E6}
{083C21F2-8C37-4E30-9CA8-82AAD4F77DD9} = {3CA6C44F-1F49-4D5D-A26F-92046B51B4F5}
{16659358-8B04-4FAD-80A0-467982B00A9D} = {3CA6C44F-1F49-4D5D-A26F-92046B51B4F5}
{BFADD6C0-DB57-476C-A168-A1AE62DF4668} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{16476670-C168-4DDD-B6A5-069F402E6960} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{6C7AB20D-847C-48A0-92EF-C45C621E11F0} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D} = {215614E0-F85F-460E-BCAA-13368AE1E3BD}
{BF53FB30-8068-426D-BC06-B692E45CE94D} = {D3F213BB-A6EC-4DDA-9C43-59094DF2FD09}
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78} = {9A2D709F-395D-4373-9B73-FDAE4E606B64}
{076341D1-E2B7-47A8-AB79-78BFD7DBA646} = {BF2B8E40-4D03-41A1-8ABD-7AD1A33D5B53}
{3CAC9757-F7D3-4A37-9820-B8755EF7FF3F} = {083C21F2-8C37-4E30-9CA8-82AAD4F77DD9}
{1A70000D-DAC9-4D34-9306-7914CC837B05} = {BF2B8E40-4D03-41A1-8ABD-7AD1A33D5B53}
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Debug|x64.ActiveCfg = Debug|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Debug|x64.Build.0 = Debug|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Debug|x86.ActiveCfg = Debug|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Debug|x86.Build.0 = Debug|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Release|Any CPU.Build.0 = Release|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Release|x64.ActiveCfg = Release|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Release|x64.Build.0 = Release|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Release|x86.ActiveCfg = Release|Any CPU
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8}.Release|x86.Build.0 = Release|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Debug|x64.ActiveCfg = Debug|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Debug|x64.Build.0 = Debug|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Debug|x86.ActiveCfg = Debug|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Debug|x86.Build.0 = Debug|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Release|Any CPU.Build.0 = Release|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Release|x64.ActiveCfg = Release|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Release|x64.Build.0 = Release|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Release|x86.ActiveCfg = Release|Any CPU
{BFADD6C0-DB57-476C-A168-A1AE62DF4668}.Release|x86.Build.0 = Release|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Debug|x64.ActiveCfg = Debug|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Debug|x64.Build.0 = Debug|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Debug|x86.ActiveCfg = Debug|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Debug|x86.Build.0 = Debug|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Release|Any CPU.Build.0 = Release|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Release|x64.ActiveCfg = Release|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Release|x64.Build.0 = Release|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Release|x86.ActiveCfg = Release|Any CPU
{16476670-C168-4DDD-B6A5-069F402E6960}.Release|x86.Build.0 = Release|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Debug|x64.Build.0 = Debug|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Debug|x86.Build.0 = Debug|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Release|Any CPU.Build.0 = Release|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Release|x64.ActiveCfg = Release|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Release|x64.Build.0 = Release|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Release|x86.ActiveCfg = Release|Any CPU
{6C7AB20D-847C-48A0-92EF-C45C621E11F0}.Release|x86.Build.0 = Release|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Debug|x64.ActiveCfg = Debug|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Debug|x64.Build.0 = Debug|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Debug|x86.ActiveCfg = Debug|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Debug|x86.Build.0 = Debug|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Release|Any CPU.Build.0 = Release|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Release|x64.ActiveCfg = Release|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Release|x64.Build.0 = Release|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Release|x86.ActiveCfg = Release|Any CPU
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D}.Release|x86.Build.0 = Release|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Debug|x64.ActiveCfg = Debug|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Debug|x64.Build.0 = Debug|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Debug|x86.ActiveCfg = Debug|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Debug|x86.Build.0 = Debug|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Release|Any CPU.Build.0 = Release|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Release|x64.ActiveCfg = Release|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Release|x64.Build.0 = Release|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Release|x86.ActiveCfg = Release|Any CPU
{BF53FB30-8068-426D-BC06-B692E45CE94D}.Release|x86.Build.0 = Release|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Debug|x64.ActiveCfg = Debug|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Debug|x64.Build.0 = Debug|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Debug|x86.ActiveCfg = Debug|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Debug|x86.Build.0 = Debug|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Release|x64.ActiveCfg = Release|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Release|x64.Build.0 = Release|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Release|x86.ActiveCfg = Release|Any CPU
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78}.Release|x86.Build.0 = Release|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Debug|x64.ActiveCfg = Debug|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Debug|x64.Build.0 = Debug|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Debug|x86.ActiveCfg = Debug|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Debug|x86.Build.0 = Debug|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Release|Any CPU.Build.0 = Release|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Release|x64.ActiveCfg = Release|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Release|x64.Build.0 = Release|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Release|x86.ActiveCfg = Release|Any CPU
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C033DF64-285B-4C44-AFFC-400878C92C73} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{1C050676-278A-4DD4-8396-A27BA85A89E6} = {C033DF64-285B-4C44-AFFC-400878C92C73}
{4B29C32B-9BAF-471E-B83A-D7F5735F27B8} = {1C050676-278A-4DD4-8396-A27BA85A89E6}
{083C21F2-8C37-4E30-9CA8-82AAD4F77DD9} = {3CA6C44F-1F49-4D5D-A26F-92046B51B4F5}
{16659358-8B04-4FAD-80A0-467982B00A9D} = {3CA6C44F-1F49-4D5D-A26F-92046B51B4F5}
{BFADD6C0-DB57-476C-A168-A1AE62DF4668} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{16476670-C168-4DDD-B6A5-069F402E6960} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{6C7AB20D-847C-48A0-92EF-C45C621E11F0} = {A9CE4FEF-F010-408C-9B5E-F00DC960A792}
{75784FD0-11AA-4DB2-95AE-92DA3C3B793D} = {215614E0-F85F-460E-BCAA-13368AE1E3BD}
{BF53FB30-8068-426D-BC06-B692E45CE94D} = {D3F213BB-A6EC-4DDA-9C43-59094DF2FD09}
{5D00B0B9-E9B4-423C-AFCF-0F7CB21B2A78} = {9A2D709F-395D-4373-9B73-FDAE4E606B64}
{076341D1-E2B7-47A8-AB79-78BFD7DBA646} = {BF2B8E40-4D03-41A1-8ABD-7AD1A33D5B53}
{3CAC9757-F7D3-4A37-9820-B8755EF7FF3F} = {083C21F2-8C37-4E30-9CA8-82AAD4F77DD9}
{1A70000D-DAC9-4D34-9306-7914CC837B05} = {BF2B8E40-4D03-41A1-8ABD-7AD1A33D5B53}
{9D2DCA2F-3A9B-4258-92FB-91FDCEB714A0} = {D3F213BB-A6EC-4DDA-9C43-59094DF2FD09}
EndGlobalSection
EndGlobal
83 changes: 83 additions & 0 deletions source/CreativeCoders.MacOS.HomeBrew/BrewInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using CreativeCoders.Core;
using CreativeCoders.MacOS.HomeBrew.Import;
using CreativeCoders.ProcessUtils.Execution;

namespace CreativeCoders.MacOS.HomeBrew;

/// <summary>
/// Default <see cref="IBrewInstaller"/> implementation. Uses <see cref="IProcessExecutor{TResult}"/>
/// instances (analogous to <c>BrewUpgrader</c>) to invoke the <c>brew</c> CLI.
/// </summary>
public class BrewInstaller : IBrewInstaller
{
private readonly IProcessExecutor<string> _tapExecutor;

private readonly IProcessExecutor<string> _installFormulaExecutor;

private readonly IProcessExecutor<string> _installCaskExecutor;

public BrewInstaller(IProcessExecutorBuilder<string> processExecutorBuilder)
{
Ensure.NotNull(processExecutorBuilder);

_tapExecutor = processExecutorBuilder
.SetFileName("brew")
.SetArguments(["tap", "{{tap}}"])
.ShouldThrowOnError()
.Build();

_installFormulaExecutor = processExecutorBuilder
.SetFileName("brew")
.SetArguments(["install", "{{name}}"])
.ShouldThrowOnError()
.Build();

_installCaskExecutor = processExecutorBuilder
.SetFileName("brew")
.SetArguments(["install", "--cask", "{{token}}"])
.ShouldThrowOnError()
.Build();
}

public async Task TapAsync(string tap)
{
Ensure.IsNotNullOrWhitespace(tap);

try
{
await _tapExecutor.ExecuteAsync(new { tap }).ConfigureAwait(false);
}
catch (ProcessExecutionFailedException e)
{
throw new BrewInstallFailedException(BrewInstallTargetKind.Tap, tap, e.ErrorOutput, e.ExitCode);
}
}

public async Task InstallFormulaAsync(string name)
{
Ensure.IsNotNullOrWhitespace(name);

try
{
await _installFormulaExecutor.ExecuteAsync(new { name }).ConfigureAwait(false);
}
catch (ProcessExecutionFailedException e)
{
throw new BrewInstallFailedException(BrewInstallTargetKind.Formula, name, e.ErrorOutput, e.ExitCode);
}
}

public async Task InstallCaskAsync(string token)
{
Ensure.IsNotNullOrWhitespace(token);

try
{
await _installCaskExecutor.ExecuteAsync(new { token }).ConfigureAwait(false);
}
catch (ProcessExecutionFailedException e)
{
throw new BrewInstallFailedException(BrewInstallTargetKind.Cask, token, e.ErrorOutput, e.ExitCode);
}
}
}
97 changes: 97 additions & 0 deletions source/CreativeCoders.MacOS.HomeBrew/Export/BrewExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using CreativeCoders.Core;
using CreativeCoders.MacOS.HomeBrew.Models.Casks;
using CreativeCoders.MacOS.HomeBrew.Models.Export;
using CreativeCoders.MacOS.HomeBrew.Models.Formulae;

namespace CreativeCoders.MacOS.HomeBrew.Export;

/// <summary>
/// Default <see cref="IBrewExporter"/> implementation. Reads the installed software via
/// <see cref="IBrewInstalledSoftware"/> and projects it onto the slim
/// <see cref="BrewExportModel"/> used for the JSON export.
/// </summary>
public class BrewExporter(IBrewInstalledSoftware installedSoftware) : IBrewExporter
{
private const string DefaultFormulaTap = "homebrew/core";

private const string DefaultCaskTap = "homebrew/cask";

private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};

private readonly IBrewInstalledSoftware _installedSoftware = Ensure.NotNull(installedSoftware);

/// <inheritdoc />
public async Task<BrewExportModel> CreateExportModelAsync(bool includeDependencies)
{
var installed = await _installedSoftware.GetInstalledSoftwareAsync().ConfigureAwait(false);

return new BrewExportModel
{
Formulae = installed.Formulae
.Where(x => !x.IsInstalledAsDependency() || includeDependencies)
.Select(MapFormula)
.Where(x => !string.IsNullOrWhiteSpace(x.Name))
.ToArray(),
Casks = installed.Casks
.Select(MapCask)
.Where(x => !string.IsNullOrWhiteSpace(x.Token))
.ToArray()
};
}

/// <inheritdoc />
public async Task ExportToFileAsync(string filePath, bool includeDependencies)
{
Ensure.IsNotNullOrWhitespace(filePath);

var exportModel = await CreateExportModelAsync(includeDependencies).ConfigureAwait(false);

var directory = Path.GetDirectoryName(filePath);

if (!string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(directory);
}

await using var stream = File.Create(filePath);

await JsonSerializer.SerializeAsync(stream, exportModel, JsonOptions).ConfigureAwait(false);
}

private static BrewExportFormulaModel MapFormula(BrewFormulaModel formula)
{
return new BrewExportFormulaModel
{
Name = formula.FullName ?? formula.Name ?? string.Empty,
Tap = NormalizeTap(formula.Tap, DefaultFormulaTap)
};
}

private static BrewExportCaskModel MapCask(BrewCaskModel cask)
{
return new BrewExportCaskModel
{
Token = cask.FullToken ?? cask.Token ?? string.Empty,
Tap = NormalizeTap(cask.Tap, DefaultCaskTap)
};
}

// Returns null when the tap matches the default tap so that the exported JSON stays slim.
private static string? NormalizeTap(string? tap, string defaultTap)
{
if (string.IsNullOrWhiteSpace(tap))
{
return null;
}

return string.Equals(tap, defaultTap, StringComparison.OrdinalIgnoreCase)
? null
: tap;
}
}
29 changes: 29 additions & 0 deletions source/CreativeCoders.MacOS.HomeBrew/Export/IBrewExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CreativeCoders.MacOS.HomeBrew.Models.Export;

namespace CreativeCoders.MacOS.HomeBrew.Export;

/// <summary>
/// Exports the locally installed Homebrew software to a serializable model or to a JSON file.
/// </summary>
public interface IBrewExporter
{
/// <summary>
/// Builds a <see cref="BrewExportModel"/> based on the currently installed Homebrew software.
/// </summary>
/// <param name="includeDependencies">
/// <see langword="true"/> to include formulae installed as dependencies;
/// otherwise, <see langword="false"/>.
/// </param>
/// <returns>A <see cref="BrewExportModel"/> representing the installed software.</returns>
Task<BrewExportModel> CreateExportModelAsync(bool includeDependencies);

/// <summary>
/// Builds the export model and writes it as JSON to the file at <paramref name="filePath"/>.
/// </summary>
/// <param name="filePath">The absolute or relative path of the target file.</param>
/// <param name="includeDependencies">
/// <see langword="true"/> to include formulae installed as dependencies;
/// otherwise, <see langword="false"/>.
/// </param>
Task ExportToFileAsync(string filePath, bool includeDependencies);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using CreativeCoders.MacOS.HomeBrew.Export;
using CreativeCoders.MacOS.HomeBrew.Import;
using CreativeCoders.ProcessUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -13,6 +15,9 @@ public static IServiceCollection AddHomeBrew(this IServiceCollection services)
services.TryAddSingleton<IBrewInfo, BrewInfo>();
services.TryAddSingleton<IBrewInstalledSoftware, BrewInstalledSoftware>();
services.TryAddSingleton<IBrewUpgrader, BrewUpgrader>();
services.TryAddSingleton<IBrewExporter, BrewExporter>();
services.TryAddSingleton<IBrewInstaller, BrewInstaller>();
services.TryAddSingleton<IBrewImporter, BrewImporter>();

return services;
}
Expand Down
16 changes: 16 additions & 0 deletions source/CreativeCoders.MacOS.HomeBrew/IBrewInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CreativeCoders.MacOS.HomeBrew;

/// <summary>
/// Wraps the <c>brew</c> CLI calls needed to add taps and install formulae or casks.
/// </summary>
public interface IBrewInstaller
{
/// <summary>Adds a Homebrew tap (<c>brew tap &lt;tap&gt;</c>).</summary>
Task TapAsync(string tap);

/// <summary>Installs a formula (<c>brew install &lt;name&gt;</c>).</summary>
Task InstallFormulaAsync(string name);

/// <summary>Installs a cask (<c>brew install --cask &lt;token&gt;</c>).</summary>
Task InstallCaskAsync(string token);
}
Loading
Loading