Skip to content

Commit

Permalink
Refactor bootstrap command to use UpdateOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Nov 20, 2014
1 parent a2ad304 commit a1f73c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
32 changes: 5 additions & 27 deletions carthage/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ public struct BootstrapCommand: CommandType {
public let function = "Checks out and builds the locked dependency versions of the project"

public func run(mode: CommandMode) -> Result<()> {
return ColdSignal.fromResult(BootstrapOptions.evaluate(mode))
// Reuse UpdateOptions, since all `bootstrap` flags should correspond to
// `update` flags.
return ColdSignal.fromResult(UpdateOptions.evaluate(mode))
.map { options -> ColdSignal<()> in
let directoryURL = NSURL.fileURLWithPath(options.directoryPath, isDirectory: true)!
let buildSignal = BuildCommand().buildWithOptions(BuildOptions(configuration: options.configuration, skipCurrent: true, directoryPath: options.directoryPath))

return ColdSignal.fromResult(Project.loadFromDirectory(directoryURL))
.on(next: { project in
project.preferHTTPS = !options.useSSH
project.projectEvents.observe(ProjectEventSink())
})
return ColdSignal.fromResult(options.checkoutOptions.loadProject())
.map { project -> ColdSignal<()> in
return ColdSignal.lazy {
if NSFileManager.defaultManager().fileExistsAtPath(project.cartfileLockURL.path!) {
Expand All @@ -37,26 +32,9 @@ public struct BootstrapCommand: CommandType {
}
}
.merge(identity)
.then(buildSignal)
.then(options.buildSignal)
}
.merge(identity)
.wait()
}
}

private struct BootstrapOptions: OptionsType {
let configuration: String
let directoryPath: String
let useSSH: Bool

static func create(configuration: String)(useSSH: Bool)(directoryPath: String) -> BootstrapOptions {
return self(configuration: configuration, directoryPath: directoryPath, useSSH: useSSH)
}

static func evaluate(m: CommandMode) -> Result<BootstrapOptions> {
return create
<*> m <| Option(key: "configuration", defaultValue: "Release", usage: "the Xcode configuration to build (if --build is enabled)")
<*> m <| Option(key: "use-ssh", defaultValue: false, usage: "whether to use SSH for GitHub repositories")
<*> m <| Option(defaultValue: NSFileManager.defaultManager().currentDirectoryPath, usage: "the directory containing the Carthage project")
}
}
36 changes: 24 additions & 12 deletions carthage/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,43 @@ public struct UpdateCommand: CommandType {
public func run(mode: CommandMode) -> Result<()> {
return ColdSignal.fromResult(UpdateOptions.evaluate(mode))
.map { options -> ColdSignal<()> in
var buildSignal: ColdSignal<()> = .empty()
if options.buildAfterUpdate {
buildSignal = BuildCommand().buildWithOptions(BuildOptions(configuration: options.configuration, skipCurrent: true, directoryPath: options.checkoutOptions.directoryPath))
}

return ColdSignal.fromResult(options.checkoutOptions.loadProject())
.map { $0.updateDependencies() }
.merge(identity)
.then(buildSignal)
.then(options.buildSignal)
}
.merge(identity)
.wait()
}
}

private struct UpdateOptions: OptionsType {
let buildAfterUpdate: Bool
let configuration: String
let checkoutOptions: CheckoutOptions
public struct UpdateOptions: OptionsType {
public let buildAfterUpdate: Bool
public let configuration: String
public 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()
}
}

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

static func evaluate(m: CommandMode) -> Result<UpdateOptions> {
public static func evaluate(m: CommandMode) -> Result<UpdateOptions> {
return create
<*> m <| Option(key: "configuration", defaultValue: "Release", usage: "the Xcode configuration to build (if --build is enabled)")
<*> m <| Option(key: "build", defaultValue: true, usage: "whether to build dependencies after updating")
Expand Down

0 comments on commit a1f73c1

Please sign in to comment.