import ArgumentParser import CliDoc import CommandClient import ConfigurationClient import Dependencies struct GenerateConfigurationCommand: AsyncParsableCommand { static let commandName = "generate-config" static let configuration = CommandConfiguration( commandName: commandName, abstract: createAbstract("Generate a local configuration file."), 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( name: .shortAndLong, help: "Directory to generate the configuration in.", completion: .directory ) var path: String? @Flag( name: .shortAndLong, 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 { try await _run() } private func _run() async throws { @Dependency(\.configurationClient) var configurationClient try await globals.loggingOptions(commandName: Self.commandName).withLogger { @Dependency(\.logger) var logger let output = try await configurationClient.generate(.init( force: force, json: json, path: path != nil ? .directory(path!) : nil )) print(output) } } }