Functions
The following functions are available globally.
-
Runs a bash shell command.
Declaration
Swift
@discardableResult public func run(bash bashcommand: String, combineOutput: Bool = false) -> RunOutputParameters
bashcommandthe bash shell command.
combineOutputif true then stdout and stderror go to the same stream. Default is false.
-
Runs bash command and returns before it is finished.
Declaration
Swift
public func runAsync(bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommandParameters
bashcommandthe bash shell command.
-
Runs bash command and returns before it is finished. Any output is printed to standard output and standard error, respectively.
Declaration
Swift
public func runAsyncAndPrint(bash bashcommand: String, file: String = #file, line: Int = #line) -> PrintedAsyncCommandParameters
bashcommandthe bash shell command.
-
Runs bash command and prints output and errors.
Throws
a CommandError.returnedErrorCode if the return code is anything but 0.Declaration
Swift
public func runAndPrint(bash bashcommand: String) throwsParameters
bashcommandthe bash shell command.
-
Prints message to standard error and terminates the application.
In debug builds it precedes the message with filename and line number.
Declaration
Swift
public func exit<T>(errormessage: T, errorcode: Int = 1, file: String = #file, line: Int = #line) -> NeverParameters
errormessagethe error message.
errorcodeexit code for the entire program. Defaults to 1.
Return Value
Never.
-
Prints error to standard error and terminates the application.
Declaration
Swift
public func exit(_ error: Error, file: String = #file, line: Int = #line) -> NeverParameters
errorthe error
Return Value
Never.
-
Runs a command.
Declaration
Swift
@discardableResult public func run(_ executable: String, _ args: Any..., combineOutput: Bool = false) -> RunOutputParameters
executablepath to an executable, or the name of an executable in PATH.
argsthe arguments, one string for each.
combineOutputif true then stdout and stderror go to the same stream. Default is false.
-
Runs executable and returns before it is finished.
Warning
Application will be terminated if ‘executable’ could not be launched.Declaration
Swift
public func runAsync(_ executable: String, _ args: Any..., file: String = #file, line: Int = #line) -> AsyncCommandParameters
executablePath to an executable file. If not then exit.
argsArguments to the executable.
-
Runs executable and returns before it is finished. Any output is printed to standard output and standard error, respectively.
Warning
Application will be terminated if ‘executable’ could not be launched.Declaration
Swift
public func runAsyncAndPrint(_ executable: String, _ args: Any..., file: String = #file, line: Int = #line) -> PrintedAsyncCommandParameters
executablePath to an executable file. If not then exit.
argsArguments to the executable.
-
Runs executable and prints output and errors.
Throws
CommandError.returnedErrorCode(command: String, errorcode: Int)if the exit code is anything but 0.CommandError.inAccessibleExecutable(path: String)if ‘executable’ turned out to be not so executable after all.Declaration
Swift
public func runAndPrint(_ executable: String, _ args: Any...) throwsParameters
executablepath to an executable file.
argsarguments to the executable.
-
Appends file or directory url to directory url
Declaration
Swift
public func + (leftpath: URL, rightpath: String) -> URL -
Opens a file for reading, throws if an error occurs.
Declaration
Swift
public func open(_ path: String, encoding: String.Encoding = main.encoding) throws -> ReadableStream -
Opens a file for reading, throws if an error occurs.
Declaration
Swift
public func open(_ path: URL, encoding: String.Encoding = main.encoding) throws -> ReadableStream -
Opens a file for writing, creates it first if it doesn’t exist. If the file already exists and overwrite=false, the writing will begin at the end of the file.
Declaration
Swift
public func open(forWriting path: URL, overwrite: Bool = false, encoding: String.Encoding = main.encoding) throws -> WritableStreamParameters
overwriteIf true, replace the file if it exists.
-
Opens a file for writing, creates it first if it doesn’t exist. If the file already exists and overwrite=false, the writing will begin at the end of the file.
Declaration
Swift
public func open(forWriting path: String, overwrite: Bool = false, encoding: String.Encoding = main.encoding) throws -> WritableStreamParameters
overwriteIf true, replace the file if it exists.
-
Creates a pair of streams. What is written to the 1st one can be read from the 2nd one.
Declaration
Swift
public func streams() -> (WritableStream, ReadableStream)
View on GitHub
Functions Reference