diff --git a/Sources/CliClient/CliClient+Commands.swift b/Sources/CliClient/CliClient+Commands.swift index 1c58320..b059c2c 100644 --- a/Sources/CliClient/CliClient+Commands.swift +++ b/Sources/CliClient/CliClient+Commands.swift @@ -25,16 +25,24 @@ public extension CliClient { func installDependencies( quiet: Bool = false, - shell: String? = nil + shell: String? = nil, + extraArgs: [String]? = nil ) async throws { guard let url = Bundle.module.url(forResource: "Brewfile", withExtension: nil) else { throw CliClientError.brewfileNotFound } + var arguments = [ + "brew", "bundle", + "--file", url.cleanFilePath + ] + if let extraArgs { + arguments.append(contentsOf: extraArgs) + } + try await runCommand( quiet: quiet, shell: shell.orDefault, - "brew", "bundle", - "--file", url.cleanFilePath + arguments ) } diff --git a/Sources/hpa/BuildCommand.swift b/Sources/hpa/BuildCommand.swift index 726b4a9..e8e315a 100644 --- a/Sources/hpa/BuildCommand.swift +++ b/Sources/hpa/BuildCommand.swift @@ -21,9 +21,9 @@ struct BuildCommand: AsyncParsableCommand { var projectDir: String @Argument( - help: "Extra arguments passed to the playbook." + help: "Extra arguments / options passed to the playbook." ) - var extraArgs: [String] = [] + var extraOptions: [String] = [] mutating func run() async throws { try await _run() diff --git a/Sources/hpa/CreateCommand.swift b/Sources/hpa/CreateCommand.swift index b611a24..3506e5d 100644 --- a/Sources/hpa/CreateCommand.swift +++ b/Sources/hpa/CreateCommand.swift @@ -54,7 +54,7 @@ struct CreateCommand: AsyncParsableCommand { @Argument( help: "Extra arguments passed to the playbook." ) - var extraArgs: [String] = [] + var extraOptions: [String] = [] mutating func run() async throws { try await _run() @@ -81,7 +81,7 @@ struct CreateCommand: AsyncParsableCommand { "--tags", "setup-project", "--extra-vars", "project_dir=\(self.projectDir)", "--extra-vars", "'\(json)'" - ] + extraArgs + ] + extraOptions try await cliClient.runPlaybookCommand( globals.playbookOptions( diff --git a/Sources/hpa/Internal/CommandConfigurationExtensions.swift b/Sources/hpa/Internal/CommandConfigurationExtensions.swift index c22e0b9..724faca 100644 --- a/Sources/hpa/Internal/CommandConfigurationExtensions.swift +++ b/Sources/hpa/Internal/CommandConfigurationExtensions.swift @@ -25,7 +25,13 @@ func createAbstract(_ string: String) -> String { extension Usage where Content == AnyTextNode { - static func `default`(commandName: String, parentCommand: String?) -> Self { + static func `default`( + commandName: String, + parentCommand: String?, + usesArguments: Bool = true, + usesOptions: Bool = true, + usesExtraArguments: Bool = true + ) -> Self { .init { HStack { HStack { @@ -37,10 +43,16 @@ extension Usage where Content == AnyTextNode { } .color(.blue).bold() - "[OPTIONS]".color(.green) - "[ARGUMENTS]".color(.cyan) - "--" - "[EXTRA-OPTIONS]".color(.magenta) + if usesOptions { + "[OPTIONS]".color(.green) + } + if usesArguments { + "[ARGUMENTS]".color(.cyan) + } + if usesExtraArguments { + "--" + "[EXTRA-OPTIONS]".color(.magenta) + } } .eraseToAnyTextNode() diff --git a/Sources/hpa/UtilsCommands/CreateTemplateCommand.swift b/Sources/hpa/UtilsCommands/CreateTemplateCommand.swift index a599abf..4e24d24 100644 --- a/Sources/hpa/UtilsCommands/CreateTemplateCommand.swift +++ b/Sources/hpa/UtilsCommands/CreateTemplateCommand.swift @@ -34,9 +34,9 @@ struct GenerateProjectTemplateCommand: AsyncParsableCommand { var path: String @Argument( - help: "Extra arguments passed to the playbook." + help: "Extra arguments / options passed to the playbook." ) - var extraArgs: [String] = [] + var extraOptions: [String] = [] mutating func run() async throws { @Dependency(\.cliClient) var cliClient diff --git a/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift b/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift index 304f96d..a566d05 100644 --- a/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift +++ b/Sources/hpa/UtilsCommands/InstallDependenciesCommand.swift @@ -9,6 +9,7 @@ struct InstallDependenciesCommand: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: commandName, abstract: createAbstract("Ensure required dependencies are installed"), + usage: .default(commandName: commandName, parentCommand: "utils", usesArguments: false), discussion: Discussion { VStack { Note { @@ -18,6 +19,7 @@ struct InstallDependenciesCommand: AsyncParsableCommand { "See Also:".yellow.bold.underline "https://brew.sh" } + ImportantNote.passingExtraArgs } .separator(.newLine(count: 2)) } @@ -25,11 +27,17 @@ struct InstallDependenciesCommand: AsyncParsableCommand { @OptionGroup var globals: BasicGlobalOptions + @Argument( + help: "Extra arguments / options to pass to the homebrew command." + ) + var extraOptions: [String] + mutating func run() async throws { @Dependency(\.cliClient) var cliClient try await cliClient.installDependencies( quiet: globals.quiet, - shell: globals.shell + shell: globals.shell, + extraArgs: extraOptions ) } } diff --git a/Sources/hpa/VaultCommands/EncryptCommand.swift b/Sources/hpa/VaultCommands/EncryptCommand.swift index f554de8..d916dd2 100644 --- a/Sources/hpa/VaultCommands/EncryptCommand.swift +++ b/Sources/hpa/VaultCommands/EncryptCommand.swift @@ -19,7 +19,6 @@ struct EncryptCommand: AsyncParsableCommand { ) var output: String? - // FIX: mutating func run() async throws { @Dependency(\.cliClient) var cliClient @@ -31,11 +30,5 @@ struct EncryptCommand: AsyncParsableCommand { options.vaultOptions(arguments: args, configuration: nil), logging: options.loggingOptions(commandName: Self.commandName) ) - -// try await runVault( -// commandName: Self.commandName, -// options: options, -// args -// ) } }