feat: Reorganizes files
This commit is contained in:
56
Sources/hpa/UtilsCommands/CreateTemplateCommand.swift
Normal file
56
Sources/hpa/UtilsCommands/CreateTemplateCommand.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
import ArgumentParser
|
||||
|
||||
struct CreateProjectTemplateCommand: AsyncParsableCommand {
|
||||
|
||||
static let commandName = "create-template"
|
||||
|
||||
static let configuration = CommandConfiguration.playbookCommandConfiguration(
|
||||
commandName: commandName,
|
||||
abstract: "Create a home performance assesment project template.",
|
||||
examples: (label: "Create 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 passed to the playbook."
|
||||
)
|
||||
var extraArgs: [String] = []
|
||||
|
||||
mutating func run() async throws {
|
||||
let varsDir = templateVars != nil
|
||||
? ["--extra-vars", "repo_vars_dir=\(templateVars!)"]
|
||||
: []
|
||||
|
||||
let vault = noVault ? ["--extra-vars", "use_vault=false"] : []
|
||||
|
||||
try await runPlaybook(
|
||||
commandName: Self.commandName,
|
||||
globals: globals,
|
||||
extraArgs: extraArgs,
|
||||
[
|
||||
"--tags", "repo-template",
|
||||
"--extra-vars", "output_dir=\(path)"
|
||||
] + varsDir
|
||||
+ vault
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user