Skip to content

Commit

Permalink
Merge pull request #19 from vapor/gm
Browse files Browse the repository at this point in the history
gm updates
  • Loading branch information
tanner0101 authored Sep 8, 2016
2 parents 234904f + 148f3b5 commit cab9dcb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-08-18-a
DEVELOPMENT-SNAPSHOT-2016-09-06-a
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ let package = Package(
name: "Console",
targets: [
Target(name: "Console"),
Target(name: "ConsoleExample", dependencies: ["Console"])
// Target(name: "ConsoleExample", dependencies: ["Console"])
],
dependencies: [
.Package(url: "https://github.com/vapor/polymorphic.git", majorVersion: 0, minor: 4),
.Package(url: "https://github.com/vapor/core.git", majorVersion: 0, minor: 4),
.Package(url: "https://github.com/vapor/core.git", majorVersion: 0, minor: 5),
],
exclude: [
"Sources/ConsoleExample"
]
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Travis builds this package on both Ubuntu 14.04 and macOS 10.11. Check out the `

|Console|Xcode|Swift|
|:-:|:-:|:-:|
|0.7.x|8.0 GM|DEVELOPMENT-SNAPSHOT-2016-09-06-a|
|0.6.x|8.0 Beta **6**|DEVELOPMENT-SNAPSHOT-2016-08-18-a|
|0.5.x|8.0 Beta **3**|DEVELOPMENT-SNAPSHOT-2016-07-25-a|
|0.4.x|8.0 Beta **3**|DEVELOPMENT-SNAPSHOT-2016-07-20-qutheory|
Expand Down
19 changes: 8 additions & 11 deletions Sources/Console/Console/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@ public protocol ConsoleProtocol {

extension ConsoleProtocol {
public func foregroundExecute(program: String, arguments: [String]) throws {
#if os(Linux)
let stdin = FileHandle.standardInput()
let stdout = FileHandle.standardOutput()
let stderr = FileHandle.standardError()
#else
let stdin = FileHandle.standardInput
let stdout = FileHandle.standardOutput
let stderr = FileHandle.standardError
#endif
let stdin = FileHandle.standardInput
let stdout = FileHandle.standardOutput
let stderr = FileHandle.standardError

try execute(
program: program,
Expand Down Expand Up @@ -116,8 +110,11 @@ extension ConsoleProtocol {
)
} catch ConsoleError.execute(let result) {
close(error.fileHandleForWriting.fileDescriptor)
let error = String(data: error.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "Unknown"
throw ConsoleError.backgroundExecute(result, error)
close(output.fileHandleForWriting.fileDescriptor)
let error = try error.fileHandleForReading.readDataToEndOfFile().makeBytes()
let output = try output.fileHandleForReading.readDataToEndOfFile().makeBytes()

throw ConsoleError.backgroundExecute(code: result, error: error, output: output)
}

close(output.fileHandleForWriting.fileDescriptor)
Expand Down
6 changes: 4 additions & 2 deletions Sources/Console/Console/ConsoleError.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Core

public enum ConsoleError: Swift.Error {
case help
case noExecutable
Expand All @@ -7,7 +9,7 @@ public enum ConsoleError: Swift.Error {
case commandNotFound(String)
case cancelled
case spawnProcess
case execute(Int)
case backgroundExecute(Int, String)
case execute(code: Int)
case backgroundExecute(code: Int, error: Bytes, output: Bytes)
case fileOrDirectoryNotFound
}
2 changes: 1 addition & 1 deletion Sources/Console/Terminal/Terminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public class Terminal: ConsoleProtocol {
if result == ENOENT {
throw ConsoleError.fileOrDirectoryNotFound
} else if result != 0 {
throw ConsoleError.execute(Int(result))
throw ConsoleError.execute(code: Int(result))
}
}

Expand Down
7 changes: 1 addition & 6 deletions Tests/ConsoleTests/ConsoleTests.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import XCTest

#if os(Linux)
import Glibc
#else
import Darwin
#endif

import libc

@testable import Console

Expand Down

0 comments on commit cab9dcb

Please sign in to comment.