Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.79 KB

README.md

File metadata and controls

53 lines (39 loc) · 1.79 KB

Die, μ-framework to exit swift scripts

Build Status codecov.io Swift 4.2 Carthage compatible

Usage

Calling die() or die("Oh no!") prints the name of the file, the location of the error and the optional message and calls exit(EXIT_FAILURE) afterwards. There also are multiple convenience functions to work with throwing functions:

dieOnThrow {
    try maybeThrowingFunction(["Please", "don't", "throw"])
}

Or using the message parameter to supply a failure reason:

dieOnThrow("Failed to compute the answer") {
    guard someValue == 42 else { throw SomeError }
}

And for working with throwing functions and using the result:

let contents = dieOnThrow("Unable to get the contents of \(someURL)") {
    let contents = try fm.contentsOfDirectoryAtURL(someURL, includingPropertiesForKeys: nil, options: [])
    // Do more stuff...
    return contents
}

Additionaly there are functions to die in case an expression evaluates to nil, or not to nil:

let result = dieIfNil(someObject.methodThatMightReturnNil())
dieIfNotNil(someObject.methodThatReturnsAnError())

As well as for true or false:

dieIfFalse(fm.isDeletableFileAtPath(sourcePath))

dieOnThrow("Failed to delete \(sourcePath)") {
    try fm.removeItemAtPath(sourcePath)
}

dieIfTrue(fm.fileExistsAtURL(sourceURL))

Installation

Add github "daehn/die" to your Cartfile