<commit_before>//
//  Update.swift
//  Carthage
//
//  Created by <NAME> on 2014-11-12.
//  Copyright (c) 2014 Carthage. All rights reserved.
//

import CarthageKit
import Commandant
import Foundation
import LlamaKit
import ReactiveCocoa

public struct UpdateCommand: CommandType {
	public let verb = "update"
	public let function = "Update and rebuild the project's dependencies"

	public func run(mode: CommandMode) -> Result<()> {
		return ColdSignal.fromResult(UpdateOptions.evaluate(mode))
			.map { options -> ColdSignal<()> in
				return options.loadProject()
					.map { $0.updateDependencies() }
					.merge(identity)
					.then(options.buildSignal)
			}
			.merge(identity)
			.wait()
	}
}

public struct UpdateOptions: OptionsType {
	public let buildAfterUpdate: Bool
	public let configuration: String
	private let checkoutOptions: CheckoutOptions

	/// The build options corresponding to these options.
	public var buildOptions: BuildOptions {
		return BuildOptions(configuration: configuration, skipCurrent: true, directoryPath: checkoutOptions.directoryPath)
	}

	/// If `buildAfterUpdate` is true, this will be a signal representing the
	/// work necessary to build the project.
	///
	/// Otherwise, this signal will be empty.
	public var buildSignal: ColdSignal<()> {
		if buildAfterUpdate {
			return BuildCommand().buildWithOptions(buildOptions)
		} else {
			return .empty()
		}
	}

	public static func create(color: ColorOptions)(configuration: String)(buildAfterUpdate: Bool)(checkoutOptions: CheckoutOptions) -> UpdateOptions {
		return self(buildAfterUpdate: buildAfterUpdate, configuration: configuration, checkoutOptions: checkoutOptions)
	}

	public static func evaluate(m: CommandMode) -> Result<UpdateOptions> {
		return create
			<*> ColorOptions.evaluate(m)
			<*> m <| Option(key: "configuration", defaultValue: "Release", usage: "the Xcode configuration to build (ignored if --no-build option is present)")
			<*> m <| Option(key: "build", defaultValue: true, usage: "skip the building of dependencies after updating")
			<*> CheckoutOptions.evaluate(m, useBinariesAddendum: " (ignored if --no-build option is present)")
	}

	/// Attempts to load the project referenced by the options, and configure it
	/// accordingly.
	public func loadProject() -> ColdSignal<Project> {
		return checkoutOptions.loadProject().on(next: { project in
			// Never check out binaries if we're skipping the build step,
			// because that means users may need the repository checkout.
			if !self.buildAfterUpdate {
				project.useBinaries = false
			}
		})
	}
}
<commit_msg>Remove `ColorOptions.evaluate` from `UpdateOptions.evaluate`.<commit_after>//
//  Update.swift
//  Carthage
//
//  Created by <NAME> on 2014-11-12.
//  Copyright (c) 2014 Carthage. All rights reserved.
//

import CarthageKit
import Commandant
import Foundation
import LlamaKit
import ReactiveCocoa

public struct UpdateCommand: CommandType {
	public let verb = "update"
	public let function = "Update and rebuild the project's dependencies"

	public func run(mode: CommandMode) -> Result<()> {
		return ColdSignal.fromResult(UpdateOptions.evaluate(mode))
			.map { options -> ColdSignal<()> in
				return options.loadProject()
					.map { $0.updateDependencies() }
					.merge(identity)
					.then(options.buildSignal)
			}
			.merge(identity)
			.wait()
	}
}

public struct UpdateOptions: OptionsType {
	public let buildAfterUpdate: Bool
	public let configuration: String
	private let checkoutOptions: CheckoutOptions

	/// The build options corresponding to these options.
	public var buildOptions: BuildOptions {
		return BuildOptions(configuration: configuration, skipCurrent: true, directoryPath: checkoutOptions.directoryPath)
	}

	/// If `buildAfterUpdate` is true, this will be a signal representing the
	/// work necessary to build the project.
	///
	/// Otherwise, this signal will be empty.
	public var buildSignal: ColdSignal<()> {
		if buildAfterUpdate {
			return BuildCommand().buildWithOptions(buildOptions)
		} else {
			return .empty()
		}
	}

	public static func create(configuration: String)(buildAfterUpdate: Bool)(checkoutOptions: CheckoutOptions) -> UpdateOptions {
		return self(buildAfterUpdate: buildAfterUpdate, configuration: configuration, checkoutOptions: checkoutOptions)
	}

	public static func evaluate(m: CommandMode) -> Result<UpdateOptions> {
		return create
			<*> m <| Option(key: "configuration", defaultValue: "Release", usage: "the Xcode configuration to build (ignored if --no-build option is present)")
			<*> m <| Option(key: "build", defaultValue: true, usage: "skip the building of dependencies after updating")
			<*> CheckoutOptions.evaluate(m, useBinariesAddendum: " (ignored if --no-build option is present)")
	}

	/// Attempts to load the project referenced by the options, and configure it
	/// accordingly.
	public func loadProject() -> ColdSignal<Project> {
		return checkoutOptions.loadProject().on(next: { project in
			// Never check out binaries if we're skipping the build step,
			// because that means users may need the repository checkout.
			if !self.buildAfterUpdate {
				project.useBinaries = false
			}
		})
	}
}

{'fraction_non_alphanumeric': 0.10567060189665183, 'fraction_numerical': 0.005031933423650087, 'mean_word_length': 4.22020202020202, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3073942', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1415, 'n_words': 473}