-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install.swift
executable file
·61 lines (49 loc) · 1.57 KB
/
Install.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
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env swift
import Foundation
let red = "\u{001B}[0;31m"
let green = "\u{001B}[0;32m"
let yellow = "\u{001B}[0;33m"
let cyan = "\u{001B}[0;36m"
let reset = "\u{001B}[0m"
let checkmark = "\u{2713}"
let cross = "\u{2717}"
let alert = "\u{26A0}"
func step(_ message: String, command: String) {
let spinners = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧"]
let queue = DispatchQueue.global(qos: .userInteractive)
let errorPipe = Pipe()
let process = Process()
process.executableURL = URL(filePath: "/bin/bash")
process.arguments = ["-c", command]
process.standardOutput = FileHandle(forWritingAtPath: "/dev/null")!
process.standardError = errorPipe
var i = 0
var running = true
queue.async {
while running {
print("\r\(message): \(cyan)\(spinners[i])\(reset)", terminator: "")
fflush(stdout)
i = (i + 1) % spinners.count
Thread.sleep(forTimeInterval: 0.1)
}
}
process.terminationHandler = { result in
running = false
if result.terminationStatus == 0 {
print("\r\(message): \(green)\(checkmark)\(reset)")
} else {
print("\r\(message): \(red)\(cross)\(reset)")
let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
if let errorOutput = String(data: errorData, encoding: .utf8), !errorOutput.isEmpty {
print("\(red)\(alert) \(errorOutput)")
}
}
}
try? process.run()
process.waitUntilExit()
}
// Homebrew
step("Update Homebrew", command: "brew update")
step("Install from Brewfile", command: "brew bundle")
print("\r")
print("\r[Setup Complete]")