♻️ 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. /// Runs the command.
public mutating func run(_ options: HomeOptions) -> Result<(), MASError> { public func run(_ options: HomeOptions) -> Result<(), MASError> {
do { do {
guard let result = try storeSearch.lookup(app: options.appId) guard let result = try storeSearch.lookup(app: options.appId)
else { else {
@ -39,10 +39,8 @@ public struct HomeCommand: CommandProtocol {
dump(result) dump(result)
let url = result.trackViewUrl
openCommand.arguments = [url]
do { do {
try openCommand.run() try openCommand.run(arguments: result.trackViewUrl)
} catch { } catch {
printError("Unable to launch open command") printError("Unable to launch open command")
return .failure(.searchFailed) return .failure(.searchFailed)

View file

@ -9,7 +9,6 @@
/// CLI command /// CLI command
public protocol ExternalCommand { public protocol ExternalCommand {
var binaryPath: String { get set } var binaryPath: String { get set }
var arguments: [String] { get set }
var process: Process { get } var process: Process { get }
@ -23,7 +22,7 @@ public protocol ExternalCommand {
var failed: Bool { get } var failed: Bool { get }
/// Runs the command. /// Runs the command.
func run() throws func run(arguments: String...) throws
} }
/// Common implementation /// Common implementation
@ -51,7 +50,7 @@ extension ExternalCommand {
}} }}
/// Runs the command. /// Runs the command.
public func run() throws { public func run(arguments: String...) throws {
process.standardOutput = stdoutPipe process.standardOutput = stdoutPipe
process.standardError = stderrPipe process.standardError = stderrPipe
process.arguments = arguments process.arguments = arguments

View file

@ -10,7 +10,6 @@
/// https://ss64.com/osx/open.html /// https://ss64.com/osx/open.html
public struct OpenCommand: ExternalCommand { public struct OpenCommand: ExternalCommand {
public var binaryPath: String public var binaryPath: String
public var arguments: [String]
public let process = Process() public let process = Process()
@ -18,10 +17,8 @@ public struct OpenCommand: ExternalCommand {
public let stderrPipe = Pipe() public let stderrPipe = Pipe()
public init( public init(
binaryPath: String = "/usr/bin/open", binaryPath: String = "/usr/bin/open"
arguments: [String] = []
) { ) {
self.binaryPath = binaryPath self.binaryPath = binaryPath
self.arguments = arguments
} }
} }

View file

@ -11,7 +11,6 @@
/// https://github.com/Homebrew/homebrew-core/blob/master/Formula/trash.rb /// https://github.com/Homebrew/homebrew-core/blob/master/Formula/trash.rb
public struct TrashCommand: ExternalCommand { public struct TrashCommand: ExternalCommand {
public var binaryPath: String public var binaryPath: String
public var arguments: [String]
public let process = Process() public let process = Process()
@ -19,10 +18,8 @@ public struct TrashCommand: ExternalCommand {
public let stderrPipe = Pipe() public let stderrPipe = Pipe()
public init( public init(
binaryPath: String = "/usr/local/bin/trash", binaryPath: String = "/usr/local/bin/trash"
arguments: [String] = []
) { ) {
self.binaryPath = binaryPath self.binaryPath = binaryPath
self.arguments = arguments
} }
} }

View file

@ -42,9 +42,8 @@ public class MasAppLibrary: AppLibrary {
/// - Parameter app: App to be removed. /// - Parameter app: App to be removed.
/// - Throws: Error if there is a problem. /// - Throws: Error if there is a problem.
public func uninstallApp(app: SoftwareProduct) throws { public func uninstallApp(app: SoftwareProduct) throws {
trashCommand.arguments = [app.bundlePath]
do { do {
try trashCommand.run() try trashCommand.run(arguments: app.bundlePath)
} catch { } catch {
printError("Unable to launch trash command") printError("Unable to launch trash command")
throw MASError.uninstallFailed throw MASError.uninstallFailed