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
|
||||
)
|
||||
}
|
||||
}
|
||||
66
Sources/hpa/UtilsCommands/GenerateConfigCommand.swift
Normal file
66
Sources/hpa/UtilsCommands/GenerateConfigCommand.swift
Normal file
@@ -0,0 +1,66 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
|
||||
struct GenerateConfigurationCommand: AsyncParsableCommand {
|
||||
|
||||
static let commandName = "generate-config"
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: commandName,
|
||||
abstract: "\("Generate a local configuration file.".blue)",
|
||||
discussion: """
|
||||
|
||||
\("NOTE:".yellow) If a directory is not supplied then a configuration file will be created
|
||||
at \("'~/.config/hpa-playbook/config'".yellow).
|
||||
|
||||
\("Example:".yellow)
|
||||
|
||||
\("Create a directory and generate the configuration file.".green)
|
||||
$ mkdir -p ~/.config/hpa-playbook
|
||||
$ hpa generate-config --path ~/.config/hpa-playbook
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Directory to generate the configuration in.",
|
||||
completion: .directory
|
||||
)
|
||||
var path: String?
|
||||
|
||||
@Flag(
|
||||
name: .shortAndLong,
|
||||
help: "Generate a json file, instead of default env style"
|
||||
)
|
||||
var json: Bool = false
|
||||
|
||||
@OptionGroup var globals: BasicGlobalOptions
|
||||
|
||||
mutating func run() async throws {
|
||||
try await _run()
|
||||
}
|
||||
|
||||
private func _run() async throws {
|
||||
try await withSetupLogger(commandName: Self.commandName, globals: globals) {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
|
||||
let actualPath: String
|
||||
|
||||
if let path {
|
||||
actualPath = "\(path)/config"
|
||||
} else {
|
||||
let path = "~/.config/hpa-playbook/"
|
||||
try await cliClient.runCommand(
|
||||
quiet: false,
|
||||
shell: globals.shellOrDefault,
|
||||
"mkdir", "-p", path
|
||||
)
|
||||
actualPath = "\(path)/config"
|
||||
}
|
||||
|
||||
try cliClient.createConfiguration(actualPath, json)
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Sources/hpa/UtilsCommands/UtilsCommand.swift
Normal file
17
Sources/hpa/UtilsCommands/UtilsCommand.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
import ArgumentParser
|
||||
|
||||
struct UtilsCommand: AsyncParsableCommand {
|
||||
static let commandName = "utils"
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: commandName,
|
||||
abstract: "\("Utility commands.".blue)",
|
||||
discussion: """
|
||||
These are commands that are generally only run on occasion / less frequently used.
|
||||
""",
|
||||
subcommands: [
|
||||
CreateProjectTemplateCommand.self, GenerateConfigurationCommand.self
|
||||
]
|
||||
)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user