♻️ Change args to be parameters of run method

This commit is contained in:
Ben Chatelain 2019-01-03 16:30:56 -08:00
parent dbf20d6d7a
commit dcf7c4954f
5 changed files with 7 additions and 17 deletions

View file

@ -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)

View file

@ -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

View file

@ -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
}
}

View file

@ -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
}
}

View file

@ -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