forked from Carthage/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fetch.swift
50 lines (43 loc) · 1.4 KB
/
Fetch.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Fetch.swift
// Carthage
//
// Created by Justin Spahr-Summers on 2014-12-24.
// Copyright (c) 2014 Carthage. All rights reserved.
//
import CarthageKit
import Commandant
import Result
import Foundation
import ReactiveCocoa
public struct FetchCommand: CommandType {
public let verb = "fetch"
public let function = "Clones or fetches a Git repository ahead of time"
public func run(mode: CommandMode) -> Result<(), CommandantError<CarthageError>> {
return producerWithOptions(FetchOptions.evaluate(mode))
|> map { options -> SignalProducer<(), CommandError> in
let project = ProjectIdentifier.Git(options.repositoryURL)
var eventSink = ProjectEventSink(colorOptions: options.colorOptions)
return cloneOrFetchProject(project, preferHTTPS: true)
|> on(next: { event, _ in
eventSink.put(event)
})
|> then(.empty)
|> promoteErrors
}
|> flatten(.Merge)
|> waitOnCommand
}
}
private struct FetchOptions: OptionsType {
let colorOptions: ColorOptions
let repositoryURL: GitURL
static func create(colorOptions: ColorOptions)(repositoryURL: GitURL) -> FetchOptions {
return self(colorOptions: colorOptions, repositoryURL: repositoryURL)
}
static func evaluate(m: CommandMode) -> Result<FetchOptions, CommandantError<CarthageError>> {
return create
<*> ColorOptions.evaluate(m)
<*> m <| Option(usage: "the Git repository that should be cloned or fetched")
}
}