diff --git a/MasKit/Commands/Home.swift b/MasKit/Commands/Home.swift index 750e631..fcebb45 100644 --- a/MasKit/Commands/Home.swift +++ b/MasKit/Commands/Home.swift @@ -29,7 +29,7 @@ public struct HomeCommand: CommandProtocol { } /// Runs the command. - public mutating func run(_ options: HomeOptions) -> Result<(), MASError> { + public func run(_ options: HomeOptions) -> Result<(), MASError> { do { guard let result = try storeSearch.lookup(app: options.appId) else { @@ -39,10 +39,8 @@ public struct HomeCommand: CommandProtocol { dump(result) - let url = result.trackViewUrl - openCommand.arguments = [url] do { - try openCommand.run() + try openCommand.run(arguments: result.trackViewUrl) } catch { printError("Unable to launch open command") return .failure(.searchFailed) diff --git a/MasKit/ExternalCommands/ExternalCommand.swift b/MasKit/ExternalCommands/ExternalCommand.swift index df50e13..3090c60 100644 --- a/MasKit/ExternalCommands/ExternalCommand.swift +++ b/MasKit/ExternalCommands/ExternalCommand.swift @@ -9,7 +9,6 @@ /// CLI command public protocol ExternalCommand { var binaryPath: String { get set } - var arguments: [String] { get set } var process: Process { get } @@ -23,7 +22,7 @@ public protocol ExternalCommand { var failed: Bool { get } /// Runs the command. - func run() throws + func run(arguments: String...) throws } /// Common implementation @@ -51,7 +50,7 @@ extension ExternalCommand { }} /// Runs the command. - public func run() throws { + public func run(arguments: String...) throws { process.standardOutput = stdoutPipe process.standardError = stderrPipe process.arguments = arguments diff --git a/MasKit/ExternalCommands/OpenCommand.swift b/MasKit/ExternalCommands/OpenCommand.swift index 2693ab5..dd8467a 100644 --- a/MasKit/ExternalCommands/OpenCommand.swift +++ b/MasKit/ExternalCommands/OpenCommand.swift @@ -10,7 +10,6 @@ /// https://ss64.com/osx/open.html public struct OpenCommand: ExternalCommand { public var binaryPath: String - public var arguments: [String] public let process = Process() @@ -18,10 +17,8 @@ public struct OpenCommand: ExternalCommand { public let stderrPipe = Pipe() public init( - binaryPath: String = "/usr/bin/open", - arguments: [String] = [] + binaryPath: String = "/usr/bin/open" ) { self.binaryPath = binaryPath - self.arguments = arguments } } diff --git a/MasKit/ExternalCommands/TrashCommand.swift b/MasKit/ExternalCommands/TrashCommand.swift index ddad5eb..74cafd9 100644 --- a/MasKit/ExternalCommands/TrashCommand.swift +++ b/MasKit/ExternalCommands/TrashCommand.swift @@ -11,7 +11,6 @@ /// https://github.com/Homebrew/homebrew-core/blob/master/Formula/trash.rb public struct TrashCommand: ExternalCommand { public var binaryPath: String - public var arguments: [String] public let process = Process() @@ -19,10 +18,8 @@ public struct TrashCommand: ExternalCommand { public let stderrPipe = Pipe() public init( - binaryPath: String = "/usr/local/bin/trash", - arguments: [String] = [] + binaryPath: String = "/usr/local/bin/trash" ) { self.binaryPath = binaryPath - self.arguments = arguments } } diff --git a/MasKit/MasAppLibrary.swift b/MasKit/MasAppLibrary.swift index dfaf02f..a98a98e 100644 --- a/MasKit/MasAppLibrary.swift +++ b/MasKit/MasAppLibrary.swift @@ -42,9 +42,8 @@ public class MasAppLibrary: AppLibrary { /// - Parameter app: App to be removed. /// - Throws: Error if there is a problem. public func uninstallApp(app: SoftwareProduct) throws { - trashCommand.arguments = [app.bundlePath] do { - try trashCommand.run() + try trashCommand.run(arguments: app.bundlePath) } catch { printError("Unable to launch trash command") throw MASError.uninstallFailed