diff --git a/Package.swift b/Package.swift index ff4c09f..9c7b059 100644 --- a/Package.swift +++ b/Package.swift @@ -40,6 +40,9 @@ let package = Package( .product(name: "Dependencies", package: "swift-dependencies"), .product(name: "DependenciesMacros", package: "swift-dependencies"), .product(name: "ShellClient", package: "swift-shell-client") + ], + resources: [ + .copy("Resources/Brewfile") ] ), .testTarget( diff --git a/Sources/CliClient/CliClient+Commands.swift b/Sources/CliClient/CliClient+Commands.swift index 3abbd77..bbe222d 100644 --- a/Sources/CliClient/CliClient+Commands.swift +++ b/Sources/CliClient/CliClient+Commands.swift @@ -23,6 +23,17 @@ public extension CliClient { try await runCommand(quiet: quiet, shell: shell, args) } + func installDependencies() async throws { + guard let url = Bundle.module.url(forResource: "Brewfile", withExtension: nil) else { + throw CliClientError.brewfileNotFound + } + try await runCommand( + quiet: false, + shell: .zsh(useDashC: true), + "brew", "bundle", "--file", url.cleanFilePath + ) + } + func runPlaybookCommand( _ options: PlaybookOptions, logging loggingOptions: LoggingOptions diff --git a/Sources/CliClient/CliClientError.swift b/Sources/CliClient/CliClientError.swift index 592ee7e..68b606d 100644 --- a/Sources/CliClient/CliClientError.swift +++ b/Sources/CliClient/CliClientError.swift @@ -1,6 +1,7 @@ import Foundation public enum CliClientError: Error { + case brewfileNotFound case encodingError case playbookDirectoryNotFound case templateDirectoryNotFound diff --git a/Sources/CliClient/Resources/Brewfile b/Sources/CliClient/Resources/Brewfile new file mode 100644 index 0000000..8c06148 --- /dev/null +++ b/Sources/CliClient/Resources/Brewfile @@ -0,0 +1,4 @@ +brew "ansible" +brew "imagemagick" +cask "mactex-no-gui" +brew "pandoc" diff --git a/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift b/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift new file mode 100644 index 0000000..8a2eb29 --- /dev/null +++ b/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift @@ -0,0 +1,23 @@ +import ArgumentParser +import CliClient +import CliDoc +import Dependencies + +struct InstallDependenciesCommand: AsyncParsableCommand { + static let commandName: String = "install-dependencies" + + static let configuration = CommandConfiguration( + commandName: commandName, + abstract: createAbstract("Ensure required dependencies are installed"), + discussion: Discussion { + Note { + "Homebrew is required to install dependencies." + } + } + ) + + func run() async throws { + @Dependency(\.cliClient) var cliClient + try await cliClient.installDependencies() + } +} diff --git a/Sources/hpa/UtilsCommands/UtilsCommand.swift b/Sources/hpa/UtilsCommands/UtilsCommand.swift index 648c6a7..ac24c4d 100644 --- a/Sources/hpa/UtilsCommands/UtilsCommand.swift +++ b/Sources/hpa/UtilsCommands/UtilsCommand.swift @@ -11,7 +11,8 @@ struct UtilsCommand: AsyncParsableCommand { """, subcommands: [ GenerateProjectTemplateCommand.self, - GenerateConfigurationCommand.self + GenerateConfigurationCommand.self, + InstallDependenciesCommand.self ] ) diff --git a/Sources/hpa/VaultCommands/DecryptCommand.swift b/Sources/hpa/VaultCommands/DecryptCommand.swift index 8b63b0f..9c1dc2d 100644 --- a/Sources/hpa/VaultCommands/DecryptCommand.swift +++ b/Sources/hpa/VaultCommands/DecryptCommand.swift @@ -19,7 +19,6 @@ struct DecryptCommand: AsyncParsableCommand { ) var output: String? - // FIX: mutating func run() async throws { @Dependency(\.cliClient) var cliClient @@ -32,11 +31,5 @@ struct DecryptCommand: AsyncParsableCommand { options.vaultOptions(arguments: args, configuration: nil), logging: options.loggingOptions(commandName: Self.commandName) ) - -// try await runVault( -// commandName: Self.commandName, -// options: options, -// args -// ) } }