feat: Removes cli-client
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
import Foundation
|
||||
import PlaybookClient
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import ConfigurationClient
|
||||
import Dependencies
|
||||
import Foundation
|
||||
@@ -71,14 +70,3 @@ struct CreateCommand: AsyncParsableCommand {
|
||||
print(projectDir)
|
||||
}
|
||||
}
|
||||
|
||||
private extension CreateCommand {
|
||||
var generateJsonOptions: CliClient.GenerateJsonOptions {
|
||||
.init(
|
||||
templateDirectory: templateDir,
|
||||
templateRepo: repo,
|
||||
version: branch,
|
||||
useLocalTemplateDirectory: localTemplateDir
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
import PandocClient
|
||||
|
||||
// TODO: Need to add a step to build prior to generating file.
|
||||
struct GenerateHtmlCommand: AsyncParsableCommand {
|
||||
@@ -13,12 +13,12 @@ struct GenerateHtmlCommand: AsyncParsableCommand {
|
||||
@OptionGroup var globals: GenerateOptions
|
||||
|
||||
mutating func run() async throws {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
@Dependency(\.pandocClient) var pandocClient
|
||||
|
||||
try await cliClient.runPandocCommand(
|
||||
globals.pandocOptions(.html),
|
||||
logging: globals.loggingOptions(commandName: Self.commandName)
|
||||
let output = try await pandocClient.run.generateHtml(
|
||||
globals.pandocRunOptions(commandName: Self.commandName)
|
||||
)
|
||||
print(output)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
|
||||
// TODO: Need to add a step to build prior to generating file.
|
||||
@@ -13,11 +12,11 @@ struct GenerateLatexCommand: AsyncParsableCommand {
|
||||
@OptionGroup var globals: GenerateOptions
|
||||
|
||||
mutating func run() async throws {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
@Dependency(\.pandocClient) var pandocClient
|
||||
|
||||
try await cliClient.runPandocCommand(
|
||||
globals.pandocOptions(.latex),
|
||||
logging: globals.loggingOptions(commandName: Self.commandName)
|
||||
let output = try await pandocClient.run.generateLatex(
|
||||
globals.pandocRunOptions(commandName: Self.commandName)
|
||||
)
|
||||
print(output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import CommandClient
|
||||
import PandocClient
|
||||
|
||||
@dynamicMemberLookup
|
||||
struct GenerateOptions: ParsableArguments {
|
||||
|
||||
@OptionGroup var basic: BasicGlobalOptions
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Custom build directory path.",
|
||||
completion: .directory
|
||||
)
|
||||
var buildDirectory: String?
|
||||
|
||||
@Option(
|
||||
name: [.short, .customLong("file")],
|
||||
help: "Files used to generate the output, can be specified multiple times.",
|
||||
@@ -65,20 +73,20 @@ struct GenerateOptions: ParsableArguments {
|
||||
|
||||
extension GenerateOptions {
|
||||
|
||||
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
|
||||
func loggingOptions(commandName: String) -> LoggingOptions {
|
||||
basic.loggingOptions(commandName: commandName)
|
||||
}
|
||||
|
||||
func pandocOptions(
|
||||
_ fileType: CliClient.PandocOptions.FileType
|
||||
) -> CliClient.PandocOptions {
|
||||
func pandocRunOptions(commandName: String) -> PandocClient.RunOptions {
|
||||
.init(
|
||||
buildDirectory: buildDirectory,
|
||||
extraOptions: extraOptions.count > 0 ? extraOptions : nil,
|
||||
files: files.count > 0 ? files : nil,
|
||||
loggingOptions: .init(commandName: commandName, logLevel: .init(globals: basic, quietOnlyPlaybook: false)),
|
||||
includeInHeader: includeInHeader.count > 0 ? includeInHeader : nil,
|
||||
outputDirectory: outputDirectory,
|
||||
outputFileName: outputFileName,
|
||||
outputFileType: fileType,
|
||||
projectDirectory: projectDirectory,
|
||||
outputFileName: outputFileName,
|
||||
quiet: basic.quiet,
|
||||
shell: basic.shell,
|
||||
shouldBuild: !noBuild
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
import PandocClient
|
||||
|
||||
// TODO: Need to add a step to build prior to generating file.
|
||||
|
||||
@@ -20,11 +20,11 @@ struct GeneratePdfCommand: AsyncParsableCommand {
|
||||
@OptionGroup var globals: GenerateOptions
|
||||
|
||||
mutating func run() async throws {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
@Dependency(\.pandocClient) var pandocClient
|
||||
|
||||
let output = try await cliClient.runPandocCommand(
|
||||
globals.pandocOptions(.pdf(engine: pdfEngine)),
|
||||
logging: globals.loggingOptions(commandName: Self.commandName)
|
||||
let output = try await pandocClient.run.generatePdf(
|
||||
globals.pandocRunOptions(commandName: Self.commandName),
|
||||
pdfEngine: pdfEngine
|
||||
)
|
||||
|
||||
print(output)
|
||||
|
||||
@@ -3,6 +3,9 @@ import Rainbow
|
||||
// Constant string values.
|
||||
enum Constants {
|
||||
static let appName = "hpa"
|
||||
static let brewPackages = [
|
||||
"ansible", "imagemagick", "pandoc", "texLive"
|
||||
]
|
||||
static let playbookFileName = "main.yml"
|
||||
static let inventoryFileName = "inventory.ini"
|
||||
static let importantExtraArgsNote = """
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import CommandClient
|
||||
import ConfigurationClient
|
||||
import PlaybookClient
|
||||
|
||||
@@ -59,10 +59,8 @@ struct GlobalOptions: ParsableArguments {
|
||||
|
||||
}
|
||||
|
||||
// TODO: Update these to use CommandClient.LoggingOptions
|
||||
|
||||
extension GlobalOptions {
|
||||
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
|
||||
func loggingOptions(commandName: String) -> LoggingOptions {
|
||||
.init(
|
||||
commandName: commandName,
|
||||
logLevel: .init(globals: basic, quietOnlyPlaybook: quietOnlyPlaybook)
|
||||
@@ -71,7 +69,7 @@ extension GlobalOptions {
|
||||
}
|
||||
|
||||
extension BasicGlobalOptions {
|
||||
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
|
||||
func loggingOptions(commandName: String) -> LoggingOptions {
|
||||
.init(
|
||||
commandName: commandName,
|
||||
logLevel: .init(globals: self, quietOnlyPlaybook: false)
|
||||
@@ -79,24 +77,6 @@ extension BasicGlobalOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
extension GlobalOptions {
|
||||
|
||||
func playbookOptions(
|
||||
arguments: [String],
|
||||
configuration: Configuration?
|
||||
) -> CliClient.PlaybookOptions {
|
||||
.init(
|
||||
arguments: arguments,
|
||||
configuration: configuration,
|
||||
inventoryFilePath: inventoryPath,
|
||||
playbookDirectory: playbookDirectory,
|
||||
quiet: quietOnlyPlaybook ? true : basic.quiet,
|
||||
shell: basic.shell
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension GlobalOptions {
|
||||
func sharedPlaybookRunOptions(
|
||||
commandName: String,
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import CliClient
|
||||
import ConfigurationClient
|
||||
|
||||
extension VaultOptions {
|
||||
|
||||
func vaultOptions(
|
||||
arguments: [String],
|
||||
configuration: Configuration?
|
||||
) -> CliClient.VaultOptions {
|
||||
.init(
|
||||
arguments: arguments,
|
||||
configuration: configuration,
|
||||
quiet: globals.quiet,
|
||||
shell: globals.shell,
|
||||
vaultFilePath: file
|
||||
)
|
||||
}
|
||||
}
|
||||
// import ConfigurationClient
|
||||
//
|
||||
// extension VaultOptions {
|
||||
//
|
||||
// func vaultOptions(
|
||||
// arguments: [String],
|
||||
// configuration: Configuration?
|
||||
// ) -> CliClient.VaultOptions {
|
||||
// .init(
|
||||
// arguments: arguments,
|
||||
// configuration: configuration,
|
||||
// quiet: globals.quiet,
|
||||
// shell: globals.shell,
|
||||
// vaultFilePath: file
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import CliDoc
|
||||
import CommandClient
|
||||
import ConfigurationClient
|
||||
import Dependencies
|
||||
|
||||
@@ -16,14 +16,14 @@ struct GenerateConfigurationCommand: AsyncParsableCommand {
|
||||
Note {
|
||||
"""
|
||||
If a directory is not supplied then a configuration file will be created
|
||||
at \("'~/.config/hpa-playbook/config'".yellow).
|
||||
at \("'~/.config/hpa/config.toml'".yellow).
|
||||
"""
|
||||
}
|
||||
VStack {
|
||||
"EXAMPLE:".yellow.bold
|
||||
"Create a directory and generate the configuration".green
|
||||
ShellCommand("mkdir -p ~/.config/hpa-playbook")
|
||||
ShellCommand("hpa generate-config --path ~/.config/hpa-playbook")
|
||||
ShellCommand("mkdir -p ~/.config/hpa")
|
||||
ShellCommand("hpa generate-config --path ~/.config/hpa")
|
||||
}
|
||||
}
|
||||
.separator(.newLine(count: 2))
|
||||
@@ -39,7 +39,7 @@ 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
|
||||
|
||||
@@ -56,26 +56,18 @@ struct GenerateConfigurationCommand: AsyncParsableCommand {
|
||||
}
|
||||
|
||||
private func _run() async throws {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
@Dependency(\.configurationClient) var configurationClient
|
||||
|
||||
try await cliClient.withLogger(globals.loggingOptions(commandName: Self.commandName)) {
|
||||
try await globals.loggingOptions(commandName: Self.commandName).withLogger {
|
||||
@Dependency(\.logger) var logger
|
||||
|
||||
let actualPath: File
|
||||
let output = try await configurationClient.generate(.init(
|
||||
force: force,
|
||||
json: json,
|
||||
path: path != nil ? .directory(path!) : nil
|
||||
))
|
||||
|
||||
if let path, let file = File("\(path)/config.\(json ? "json" : "toml")") {
|
||||
actualPath = file
|
||||
} else {
|
||||
actualPath = .default
|
||||
}
|
||||
|
||||
logger.debug("Generating config at path: \(actualPath.path)")
|
||||
|
||||
try await configurationClient.generate(
|
||||
at: actualPath,
|
||||
force: force
|
||||
)
|
||||
print(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
import PlaybookClient
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import CliDoc
|
||||
import CommandClient
|
||||
import Dependencies
|
||||
|
||||
struct InstallDependenciesCommand: AsyncParsableCommand {
|
||||
@@ -33,11 +33,20 @@ struct InstallDependenciesCommand: AsyncParsableCommand {
|
||||
var extraOptions: [String] = []
|
||||
|
||||
mutating func run() async throws {
|
||||
@Dependency(\.cliClient) var cliClient
|
||||
try await cliClient.installDependencies(
|
||||
@Dependency(\.commandClient) var commandClient
|
||||
@Dependency(\.playbookClient) var playbookClient
|
||||
|
||||
let arguments = [
|
||||
"brew", "install"
|
||||
] + Constants.brewPackages
|
||||
+ extraOptions
|
||||
|
||||
try await commandClient.run(
|
||||
quiet: globals.quiet,
|
||||
shell: globals.shell,
|
||||
extraArgs: extraOptions
|
||||
arguments
|
||||
)
|
||||
|
||||
try await playbookClient.repository.install()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
import VaultClient
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import Dependencies
|
||||
import VaultClient
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ArgumentParser
|
||||
import CliClient
|
||||
import CommandClient
|
||||
import VaultClient
|
||||
|
||||
// Holds the common options for vault commands, as they all share the
|
||||
@@ -32,12 +32,6 @@ struct VaultOptions: ParsableArguments {
|
||||
|
||||
}
|
||||
|
||||
extension VaultOptions {
|
||||
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
|
||||
globals.loggingOptions(commandName: commandName)
|
||||
}
|
||||
}
|
||||
|
||||
extension VaultOptions {
|
||||
|
||||
func runOptions(
|
||||
|
||||
Reference in New Issue
Block a user