Files
swift-hpa/Sources/hpa/UtilsCommands/GenerateProjectTemplateCommand.swift
Michael Housh faa28749bc
All checks were successful
CI / Run Tests (push) Successful in 2m43s
feat: Merges dev
2024-12-17 15:55:36 -05:00

57 lines
1.4 KiB
Swift

import ArgumentParser
import Dependencies
import PlaybookClient
struct GenerateProjectTemplateCommand: AsyncParsableCommand {
static let commandName = "generate-template"
static let configuration = CommandConfiguration.playbook(
commandName: commandName,
abstract: "Generate a home performance assesment project template.",
parentCommand: UtilsCommand.commandName,
examples: (label: "Generate Template", example: "\(commandName) /path/to/project-template")
)
@OptionGroup var globals: GlobalOptions
@Option(
name: .shortAndLong,
help: "Customize the directory where template variables are stored."
)
var templateVars: String?
@Flag(
name: .long,
help: "Do not generate ansible-vault variables file."
)
var noVault: Bool = false
@Argument(
help: "Path to the project template directory.",
completion: .directory
)
var path: String
@Argument(
help: "Extra arguments / options passed to the playbook."
)
var extraOptions: [String] = []
mutating func run() async throws {
@Dependency(\.playbookClient) var playbookClient
let output = try await playbookClient.run.generateTemplate(.init(
shared: globals.sharedPlaybookRunOptions(
commandName: Self.commandName,
extraOptions: extraOptions
),
templateDirectory: path,
templateVarsDirectory: templateVars,
useVault: !noVault
))
print(output)
}
}