feat: Begins adding docker containers

This commit is contained in:
2024-12-17 10:15:07 -05:00
parent 99459a0a71
commit f7f168b7fd
10 changed files with 114 additions and 27 deletions

View File

@@ -4,6 +4,8 @@ import Foundation
import TOMLKit
public extension DependencyValues {
/// Holds onto decoders and encoders for json and toml files.
var coders: Coders {
get { self[Coders.self] }
set { self[Coders.self] = newValue }

View File

@@ -204,7 +204,12 @@ extension ShellCommand.Shell {
if let path {
self = .custom(path: path, useDashC: true)
} else {
self = .zsh(useDashC: true)
#if os(macOS)
self = .zsh(useDashC: true)
#else
// Generally we're in a docker container when this occurs, which does not have `zsh` installed.
self = .sh(useDashC: true)
#endif
}
}
}

View File

@@ -2,13 +2,28 @@ import Foundation
// NOTE: When adding items, then the 'hpa.toml' resource file needs to be updated.
/// Represents configurable settings for the command line tool.
/// Represents configurable settings for the application.
public struct Configuration: Codable, Equatable, Sendable {
/// Default arguments / options that can get passed into
/// ansible-playbook commands.
public let args: [String]?
/// Whether to use the vault arguments as defaults that get passed into
/// the ansible-playbook commands.
public let useVaultArgs: Bool
/// Configuration for when generating files from templated directories.
public let generate: Generate?
/// Configuration of the ansible-playbook, these are more for developing the
/// playbook locally and generally not needed by the user.
public let playbook: Playbook?
/// Template configuration options.
public let template: Template
/// Ansible-vault configuration options.
public let vault: Vault
public init(

View File

@@ -3,23 +3,47 @@ import DependenciesMacros
import Foundation
public extension DependencyValues {
/// Represents interactions with the file system.
///
var fileClient: FileClient {
get { self[FileClient.self] }
set { self[FileClient.self] = newValue }
}
}
/// Represents interactions with the file system.
///
///
@DependencyClient
public struct FileClient: Sendable {
/// Copy an item from one location to another.
public var copy: @Sendable (URL, URL) async throws -> Void
/// Create a directory at the given location.
public var createDirectory: @Sendable (URL) async throws -> Void
/// Check if a file exists at the given location.
public var fileExists: @Sendable (URL) -> Bool = { _ in true }
/// Find an ansible-vault file in the given location, checking up to 1 level deep
/// in subfolders.
public var findVaultFile: @Sendable (URL) async throws -> URL?
/// Return the user's home directory.
public var homeDirectory: @Sendable () -> URL = { URL(filePath: "~/") }
/// Check if an item is a directory or not.
public var isDirectory: @Sendable (URL) async throws -> Bool
/// Load a file from the given location.
public var load: @Sendable (URL) async throws -> Data
/// Write data to a file at the given location.
public var write: @Sendable (Data, URL) async throws -> Void
/// Find an ansible-vault file in the current directory, checking up to 1 level
/// deep in subfolders.
public func findVaultFileInCurrentDirectory() async throws -> URL? {
try await findVaultFile(URL(filePath: "./"))
}
@@ -30,23 +54,16 @@ extension FileClient: DependencyKey {
public static var liveValue: Self {
let manager = LiveFileClient()
return .init {
try await manager.copy($0, to: $1)
} createDirectory: {
try await manager.creatDirectory($0)
} fileExists: { url in
manager.fileExists(at: url)
} findVaultFile: {
try await manager.findVaultFile(in: $0)
} homeDirectory: {
manager.homeDirectory()
} isDirectory: {
manager.isDirectory($0)
} load: { url in
try await manager.load(from: url)
} write: { data, url in
try await manager.write(data, to: url)
}
return .init(
copy: { try await manager.copy($0, to: $1) },
createDirectory: { try await manager.creatDirectory($0) },
fileExists: { manager.fileExists(at: $0) },
findVaultFile: { try await manager.findVaultFile(in: $0) },
homeDirectory: { manager.homeDirectory() },
isDirectory: { manager.isDirectory($0) },
load: { try await manager.load(from: $0) },
write: { try await manager.write($0, to: $1) }
)
}
}