Functions

The following functions are available globally.

  • Runs a bash shell command.

    Declaration

    Swift

    @discardableResult
    public func run(bash bashcommand: String, combineOutput: Bool = false) -> RunOutput

    Parameters

    bashcommand

    the bash shell command.

    combineOutput

    if 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) -> AsyncCommand

    Parameters

    bashcommand

    the 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) -> PrintedAsyncCommand

    Parameters

    bashcommand

    the 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) throws

    Parameters

    bashcommand

    the 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) -> Never

    Parameters

    errormessage

    the error message.

    errorcode

    exit 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) -> Never

    Parameters

    error

    the error

    Return Value

    Never.

  • Runs a command.

    Declaration

    Swift

    @discardableResult
    public func run(_ executable: String, _ args: Any..., combineOutput: Bool = false) -> RunOutput

    Parameters

    executable

    path to an executable, or the name of an executable in PATH.

    args

    the arguments, one string for each.

    combineOutput

    if 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) -> AsyncCommand

    Parameters

    executable

    Path to an executable file. If not then exit.

    args

    Arguments 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) -> PrintedAsyncCommand

    Parameters

    executable

    Path to an executable file. If not then exit.

    args

    Arguments 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...) throws

    Parameters

    executable

    path to an executable file.

    args

    arguments 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 -> WritableStream

    Parameters

    overwrite

    If 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 -> WritableStream

    Parameters

    overwrite

    If true, replace the file if it exists.