diff --git a/MasKit/Commands/Update.swift b/MasKit/Commands/Update.swift new file mode 100644 index 000000000..c8c47575e --- /dev/null +++ b/MasKit/Commands/Update.swift @@ -0,0 +1,46 @@ +// +// Update.swift +// mas-cli +// +// Created by Andrew Naylor on 30/12/2015. +// Copyright © 2015 Andrew Naylor. All rights reserved. +// + +import Commandant +import Foundation + +/// Command which updates mas. +public struct UpdateCommand: CommandProtocol { + public typealias Options = NoOptions + public let verb = "update" + public let function = "Update MAS" + + private let appLibrary: AppLibrary + + /// Public initializer. + /// - Parameter appLibrary: AppLibrary manager. + public init() { + self.init(appLibrary: MasAppLibrary()) + } + + /// Internal initializer. + /// - Parameter appLibrary: AppLibrary manager. + init(appLibrary: AppLibrary = MasAppLibrary()) { + self.appLibrary = appLibrary + } + + /// Runs the command. + public func run(_: Options) -> Result<(), MASError> { + print("Updating MAS…") + + let task = Process() + task.launchPath = getenv("HOMEBREW_BREW_FILE") + task.arguments = ["upgrade", "mas"] + //let pipe = Pipe() + //task.standardOutput = pipe + //task.standardError = pipe + task.launch() + task.waitUntilExit() + return task.terminationStatus + } +} diff --git a/mas/main.swift b/mas/main.swift index 0c9d383b2..2ac03121e 100644 --- a/mas/main.swift +++ b/mas/main.swift @@ -37,6 +37,7 @@ registry.register(SignOutCommand()) registry.register(UninstallCommand()) registry.register(RemoveCommand()) registry.register(RmCommand()) +registry.register(UpdateCommand()) registry.register(UpgradeCommand()) registry.register(VendorCommand()) registry.register(VersionCommand())