feat: Merges dev
All checks were successful
CI / Run Tests (push) Successful in 2m43s

This commit is contained in:
2024-12-17 15:55:36 -05:00
parent 857177032c
commit faa28749bc
88 changed files with 4513 additions and 2301 deletions

View File

@@ -1,5 +1,7 @@
import ArgumentParser
import CliClient
import CliDoc
import CommandClient
import ConfigurationClient
import Dependencies
struct GenerateConfigurationCommand: AsyncParsableCommand {
@@ -9,18 +11,23 @@ struct GenerateConfigurationCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: commandName,
abstract: createAbstract("Generate a local configuration file."),
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
"""
discussion: Discussion {
VStack {
Note {
"""
If a directory is not supplied then a configuration file will be created
at \("'~/.config/hpa/config.toml'".yellow).
"""
}
VStack {
"EXAMPLE:".yellow.bold
"Create a directory and generate the configuration".green
ShellCommand("mkdir -p ~/.config/hpa")
ShellCommand("hpa generate-config --path ~/.config/hpa")
}
}
.separator(.newLine(count: 2))
}
)
@Option(
@@ -32,10 +39,16 @@ struct GenerateConfigurationCommand: AsyncParsableCommand {
@Flag(
name: .shortAndLong,
help: "Generate a json file, instead of default env style"
help: "Generate a json file, instead of the default toml style"
)
var json: Bool = false
@Flag(
name: .shortAndLong,
help: "Force generation, overwriting a file if it exists."
)
var force: Bool = false
@OptionGroup var globals: BasicGlobalOptions
mutating func run() async throws {
@@ -43,24 +56,18 @@ struct GenerateConfigurationCommand: AsyncParsableCommand {
}
private func _run() async throws {
try await withSetupLogger(commandName: Self.commandName, globals: globals) {
@Dependency(\.cliClient) var cliClient
@Dependency(\.configurationClient) var configurationClient
let actualPath: String
try await globals.loggingOptions(commandName: Self.commandName).withLogger {
@Dependency(\.logger) var logger
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"
}
let output = try await configurationClient.generate(.init(
force: force,
json: json,
path: path != nil ? .directory(path!) : nil
))
try cliClient.createConfiguration(actualPath, json)
print(output)
}
}
}