diff --git a/Classes.html b/Classes.html index e24de0e..cb9e567 100644 --- a/Classes.html +++ b/Classes.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:) +
  • +
    + + + + &&(_:_:) + +
    +
    +
    +
    +
    +
    +

    Run the first command, then the second one only if the first succeeded.

    + +
    +

    Returns

    + the result of the second one if it was run, otherwise the first one. + +
    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public static func && (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
    + +
    +
    +
    +

    Return Value

    +

    the result of the second one if it was run, otherwise the first one.

    + +
    +
    +
    +
  • +
  • +
    + + + + ||(_:_:) + +
    +
    +
    +
    +
    +
    +

    Run the first command, then the second one only if the first failed.

    + +
    +

    Returns

    + the result of the second one if it was run, otherwise the first one. + +
    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public static func || (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
    + +
    +
    +
    +

    Return Value

    +

    the result of the second one if it was run, otherwise the first one.

    + +
    +
    +
    +
  • diff --git a/Classes/StdoutStream.html b/Classes/StdoutStream.html index 5c062fd..4edf400 100644 --- a/Classes/StdoutStream.html +++ b/Classes/StdoutStream.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:) diff --git a/Extensions/Process.html b/Extensions/Process.html index 9351307..3c4aa1a 100644 --- a/Extensions/Process.html +++ b/Extensions/Process.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:) +
    + +
    diff --git a/Functions.html b/Functions.html index 70fe21e..6f533d1 100644 --- a/Functions.html +++ b/Functions.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:)
  • - - - run(bash:file:line:) + + + run(bash:combineOutput:)
    @@ -212,7 +212,7 @@

    Declaration

    Swift

    -
    @discardableResult public func run (bash bashcommand: String, file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (bash bashcommand: String, combineOutput: Bool = false) -> RunOutput
    @@ -233,6 +233,19 @@ + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -242,9 +255,9 @@
  • - - - runAsync(bash:) + + + runAsync(bash:file:line:)
    @@ -259,7 +272,7 @@

    Declaration

    Swift

    -
    public func runAsync (bash bashcommand: String) -> AsyncCommand
    +
    public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
    @@ -516,9 +529,9 @@
  • - - - run(_:_:file:line:) + + + run(_:_:combineOutput:)
    @@ -528,18 +541,12 @@

    Runs a command.

    -
    -

    Warning

    - will crash if ‘executable’ could not be launched. - -
    -

    Declaration

    Swift

    -
    @discardableResult public func run (_ executable: String, _ args: Any ..., file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (_ executable: String, _ args: Any ..., combineOutput: Bool = false) -> RunOutput
    @@ -573,6 +580,19 @@
    + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -935,7 +955,7 @@ If the file already exists and overwrite=false, the writing will begin at the en diff --git a/Global Variables.html b/Global Variables.html index d35f984..7a3f85d 100644 --- a/Global Variables.html +++ b/Global Variables.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:)
  • - - - run(bash:file:line:) + + + run(bash:combineOutput:) Extension method @@ -254,7 +254,7 @@

    Declaration

    Swift

    -
    @discardableResult public func run (bash bashcommand: String, file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (bash bashcommand: String, combineOutput: Bool = false) -> RunOutput
    @@ -275,6 +275,19 @@ + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -284,9 +297,9 @@
  • - - - runAsync(bash:) + + + runAsync(bash:file:line:) Extension method @@ -304,7 +317,7 @@

    Declaration

    Swift

    -
    public func runAsync (bash bashcommand: String) -> AsyncCommand
    +
    public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
    @@ -399,9 +412,9 @@
  • - - - run(_:_:file:line:) + + + run(_:_:combineOutput:) Extension method @@ -414,18 +427,12 @@

    Runs a command.

    -
    -

    Warning

    - will crash if ‘executable’ could not be launched. - -
    -

    Declaration

    Swift

    -
    @discardableResult public func run (_ executable: String, _ args: Any ..., file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (_ executable: String, _ args: Any ..., combineOutput: Bool = false) -> RunOutput
    @@ -459,6 +466,19 @@
    + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -623,7 +643,7 @@ diff --git a/Protocols/Context.html b/Protocols/Context.html index 374ad0c..a76677f 100644 --- a/Protocols/Context.html +++ b/Protocols/Context.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:)
  • diff --git a/Structs/PartialSourceLazySplitSequence.html b/Structs/PartialSourceLazySplitSequence.html index ba80222..e155aae 100644 --- a/Structs/PartialSourceLazySplitSequence.html +++ b/Structs/PartialSourceLazySplitSequence.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:) diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes.html index e24de0e..cb9e567 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:) +
  • +
    + + + + &&(_:_:) + +
    +
    +
    +
    +
    +
    +

    Run the first command, then the second one only if the first succeeded.

    + +
    +

    Returns

    + the result of the second one if it was run, otherwise the first one. + +
    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public static func && (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
    + +
    +
    +
    +

    Return Value

    +

    the result of the second one if it was run, otherwise the first one.

    + +
    +
    +
    +
  • +
  • +
    + + + + ||(_:_:) + +
    +
    +
    +
    +
    +
    +

    Run the first command, then the second one only if the first failed.

    + +
    +

    Returns

    + the result of the second one if it was run, otherwise the first one. + +
    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public static func || (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
    + +
    +
    +
    +

    Return Value

    +

    the result of the second one if it was run, otherwise the first one.

    + +
    +
    +
    +
  • diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes/StdoutStream.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes/StdoutStream.html index 5c062fd..4edf400 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes/StdoutStream.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Classes/StdoutStream.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:) diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Extensions/Process.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Extensions/Process.html index 9351307..3c4aa1a 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Extensions/Process.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Extensions/Process.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:) +
    +
      +
    • +
      + + + + lines() + +
      +
      +
      +
      +
      +
      +

      Split text into lines (as separated by newlines).

      + +
      +
      +

      Declaration

      +
      +

      Swift

      +
      public func lines() -> [String]
      + +
      +
      +
      +
      +
    • +
    +
    diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Functions.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Functions.html index 70fe21e..6f533d1 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Functions.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Functions.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:)
  • - - - run(bash:file:line:) + + + run(bash:combineOutput:)
    @@ -212,7 +212,7 @@

    Declaration

    Swift

    -
    @discardableResult public func run (bash bashcommand: String, file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (bash bashcommand: String, combineOutput: Bool = false) -> RunOutput
    @@ -233,6 +233,19 @@ + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -242,9 +255,9 @@
  • - - - runAsync(bash:) + + + runAsync(bash:file:line:)
    @@ -259,7 +272,7 @@

    Declaration

    Swift

    -
    public func runAsync (bash bashcommand: String) -> AsyncCommand
    +
    public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
    @@ -516,9 +529,9 @@
  • - - - run(_:_:file:line:) + + + run(_:_:combineOutput:)
    @@ -528,18 +541,12 @@

    Runs a command.

    -
    -

    Warning

    - will crash if ‘executable’ could not be launched. - -
    -

    Declaration

    Swift

    -
    @discardableResult public func run (_ executable: String, _ args: Any ..., file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (_ executable: String, _ args: Any ..., combineOutput: Bool = false) -> RunOutput
    @@ -573,6 +580,19 @@
    + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -935,7 +955,7 @@ If the file already exists and overwrite=false, the writing will begin at the en diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Global Variables.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Global Variables.html index d35f984..7a3f85d 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Global Variables.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Global Variables.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:)
  • - - - run(bash:file:line:) + + + run(bash:combineOutput:) Extension method @@ -254,7 +254,7 @@

    Declaration

    Swift

    -
    @discardableResult public func run (bash bashcommand: String, file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (bash bashcommand: String, combineOutput: Bool = false) -> RunOutput
    @@ -275,6 +275,19 @@ + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -284,9 +297,9 @@
  • - - - runAsync(bash:) + + + runAsync(bash:file:line:) Extension method @@ -304,7 +317,7 @@

    Declaration

    Swift

    -
    public func runAsync (bash bashcommand: String) -> AsyncCommand
    +
    public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
    @@ -399,9 +412,9 @@
  • - - - run(_:_:file:line:) + + + run(_:_:combineOutput:) Extension method @@ -414,18 +427,12 @@

    Runs a command.

    -
    -

    Warning

    - will crash if ‘executable’ could not be launched. - -
    -

    Declaration

    Swift

    -
    @discardableResult public func run (_ executable: String, _ args: Any ..., file: String = #file, line: Int = #line) -> RunOutput
    +
    @discardableResult public func run (_ executable: String, _ args: Any ..., combineOutput: Bool = false) -> RunOutput
    @@ -459,6 +466,19 @@
    + + + + combineOutput + + + +
    +

    if true then stdout and stderror go to the same stream. Default is false.

    + +
    + + @@ -623,7 +643,7 @@ diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Protocols/Context.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Protocols/Context.html index 374ad0c..a76677f 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Protocols/Context.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Protocols/Context.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:)
  • diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs/PartialSourceLazySplitSequence.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs/PartialSourceLazySplitSequence.html index ba80222..e155aae 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs/PartialSourceLazySplitSequence.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs/PartialSourceLazySplitSequence.html @@ -118,10 +118,10 @@ open(forWriting:overwrite:encoding:) diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/index.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/index.html index b199d8e..4d126f6 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/index.html +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/index.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:)
  • Example scripts
  • @@ -235,34 +240,55 @@

    Overview

    Context

    -

    All applications (processes) have access to some information about the outside world and ways of communicating with it. This is represented in SwiftShell by the Context protocol:

    -
    public protocol Context {
    -    var env: [String: String] {get set}
    -    var currentdirectory: String {get set}
    -    var stdin: ReadableStream {get set}
    -    var stdout: WritableStream {get set}
    -    var stderror: WritableStream {get set}
    +

    All commands (a.k.a. processes) you run in SwiftShell need context: environment variables, the current working directory, standard input, standard output and standard error (see standard streams).

    +
    public struct CustomContext: Context, CommandRunning {
    +    public var env: [String: String]
    +    public var currentdirectory: String
    +    public var stdin: ReadableStream
    +    public var stdout: WritableStream
    +    public var stderror: WritableStream
     }
     
    -

    Environment variables

    -

    You can list them in the terminal with the env command.

    -

    Current working directory

    - -

    Used as the base for all relative paths. Most commands expect this to be the directory they are supposed to do stuff in.

    - -

    Commands don’t change their context.

    +

    You can create a copy of your application’s context: let context = CustomContext(main), or create a new empty one: let context = CustomContext().

    Main context

    -

    So what else can main do? It is the only global value in SwiftShell and contains all the contextual information about the outside world:

    -
    var encoding: UInt
    -lazy var tempdirectory: String
    +

    The global variable main contains the context for the application itself. In addition to the properties mentioned above it also has these:

    -lazy var arguments: [String] -lazy var name: String +
      +
    • public var encoding: String.Encoding +The default encoding used when opening files or creating new streams.
    • +
    • public let tempdirectory: String +A temporary directory the application can use for temporary stuff.
    • +
    • public let arguments: [String] +The arguments used when launching the application.
    • +
    • public let path: String +The path to the application.
    • +
    + +

    Everything is mutable, so you can set e.g. the text encoding or reroute standard error to a file. But commands can’t change the context they run in (or anything else in your application) so e.g. main.run("cd", "somefolder") will achieve nothing. Use main.currentdirectory = "somefolder" instead.

    +

    Streams

    +

    Output

    + +

    main.stdout is for normal output and main.stderror for errors. You can also write to a file:

    +
    main.stdout.print("everything is fine")
    +main.stderror.print("no wait, something went wrong ...")
    +
    +let file = try open(forWriting: path)
    +file.print("something")
     
    -

    Everything is mutable, so you can set e.g. the text encoding or reroute standard error to a file.

    +

    .write doesn’t add a newline, and you can change the text encoding with .encoding.

    +

    Input

    + +

    Use main.stdin to read from standard input, or you can read from a file:

    +
    let input: String? = main.stdin.readSome() // read what is available, don't wait for end of file 
    +
    +let file = try open(path)
    +let contents: String = file.read() // read everything
    +
    + +

    Using .readSome() you can read piecewise instead of waiting for the input to be finished and then reading everything at once. You can change the text encoding with .encoding.

    Commands

    Run

    let date: String = run("date", "-u")
    @@ -337,28 +363,6 @@
     

     

    When launched from the top level you don’t need to catch any errors, but you still have to use try.

    -

    Streams

    -

    Output

    - -

    main.stdout is for normal output and main.stderror for errors. You can also write to a file:

    -
    main.stdout.print("everything is fine")
    -main.stderror.print("no wait, something went wrong ...")
    -
    -let file = try open(forWriting: path)
    -file.print("something")
    -
    - -

    .write doesn’t add a newline, and you can change the text encoding with .encoding.

    -

    Input

    - -

    Use main.stdin to read from standard input, or you can read from a file:

    -
    let input: String? = main.stdin.readSome() // read what is available, don't wait for end of file 
    -
    -let file = try open(path)
    -let contents: String = file.read() // read everything
    -
    - -

    Using .readSome() you can read piecewise instead of waiting for the input to be finished and then reading everything at once. You can change the text encoding with .encoding.

    The Terminal

    Setup

    @@ -418,7 +422,7 @@ cd SwiftShell diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/undocumented.json b/docsets/SwiftShell.docset/Contents/Resources/Documents/undocumented.json index 4428491..9d097a9 100644 --- a/docsets/SwiftShell.docset/Contents/Resources/Documents/undocumented.json +++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/undocumented.json @@ -23,21 +23,28 @@ }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", - "line": 240, + "line": 174, + "symbol": "RunOutput.error", + "symbol_kind": "source.lang.swift.decl.var.instance", + "warning": "undocumented" + }, + { + "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", + "line": 251, "symbol": "AsyncCommand.stdout", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", - "line": 241, + "line": 252, "symbol": "AsyncCommand.stderror", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", - "line": 286, + "line": 306, "symbol": "AsyncCommand.onCompletion(handler:)", "symbol_kind": "source.lang.swift.decl.function.method.instance", "warning": "undocumented" @@ -121,42 +128,42 @@ }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 92, + "line": 93, "symbol": "MainContext", "symbol_kind": "source.lang.swift.decl.class", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 100, + "line": 101, "symbol": "MainContext.env", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 101, + "line": 102, "symbol": "MainContext.stdin", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 102, + "line": 103, "symbol": "MainContext.stdout", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 103, + "line": 104, "symbol": "MainContext.stderror", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 138, + "line": 139, "symbol": "main", "symbol_kind": "source.lang.swift.decl.var.global", "warning": "undocumented" diff --git a/docsets/SwiftShell.docset/Contents/Resources/docSet.dsidx b/docsets/SwiftShell.docset/Contents/Resources/docSet.dsidx index 6f6bfab..186dc7f 100644 Binary files a/docsets/SwiftShell.docset/Contents/Resources/docSet.dsidx and b/docsets/SwiftShell.docset/Contents/Resources/docSet.dsidx differ diff --git a/docsets/SwiftShell.tgz b/docsets/SwiftShell.tgz index 99c878d..4fc33ce 100644 Binary files a/docsets/SwiftShell.tgz and b/docsets/SwiftShell.tgz differ diff --git a/index.html b/index.html index b199d8e..4d126f6 100644 --- a/index.html +++ b/index.html @@ -117,10 +117,10 @@ open(forWriting:overwrite:encoding:)
  • Example scripts
  • @@ -235,34 +240,55 @@

    Overview

    Context

    -

    All applications (processes) have access to some information about the outside world and ways of communicating with it. This is represented in SwiftShell by the Context protocol:

    -
    public protocol Context {
    -    var env: [String: String] {get set}
    -    var currentdirectory: String {get set}
    -    var stdin: ReadableStream {get set}
    -    var stdout: WritableStream {get set}
    -    var stderror: WritableStream {get set}
    +

    All commands (a.k.a. processes) you run in SwiftShell need context: environment variables, the current working directory, standard input, standard output and standard error (see standard streams).

    +
    public struct CustomContext: Context, CommandRunning {
    +    public var env: [String: String]
    +    public var currentdirectory: String
    +    public var stdin: ReadableStream
    +    public var stdout: WritableStream
    +    public var stderror: WritableStream
     }
     
    -

    Environment variables

    -

    You can list them in the terminal with the env command.

    -

    Current working directory

    - -

    Used as the base for all relative paths. Most commands expect this to be the directory they are supposed to do stuff in.

    - -

    Commands don’t change their context.

    +

    You can create a copy of your application’s context: let context = CustomContext(main), or create a new empty one: let context = CustomContext().

    Main context

    -

    So what else can main do? It is the only global value in SwiftShell and contains all the contextual information about the outside world:

    -
    var encoding: UInt
    -lazy var tempdirectory: String
    +

    The global variable main contains the context for the application itself. In addition to the properties mentioned above it also has these:

    -lazy var arguments: [String] -lazy var name: String +
      +
    • public var encoding: String.Encoding +The default encoding used when opening files or creating new streams.
    • +
    • public let tempdirectory: String +A temporary directory the application can use for temporary stuff.
    • +
    • public let arguments: [String] +The arguments used when launching the application.
    • +
    • public let path: String +The path to the application.
    • +
    + +

    Everything is mutable, so you can set e.g. the text encoding or reroute standard error to a file. But commands can’t change the context they run in (or anything else in your application) so e.g. main.run("cd", "somefolder") will achieve nothing. Use main.currentdirectory = "somefolder" instead.

    +

    Streams

    +

    Output

    + +

    main.stdout is for normal output and main.stderror for errors. You can also write to a file:

    +
    main.stdout.print("everything is fine")
    +main.stderror.print("no wait, something went wrong ...")
    +
    +let file = try open(forWriting: path)
    +file.print("something")
     
    -

    Everything is mutable, so you can set e.g. the text encoding or reroute standard error to a file.

    +

    .write doesn’t add a newline, and you can change the text encoding with .encoding.

    +

    Input

    + +

    Use main.stdin to read from standard input, or you can read from a file:

    +
    let input: String? = main.stdin.readSome() // read what is available, don't wait for end of file 
    +
    +let file = try open(path)
    +let contents: String = file.read() // read everything
    +
    + +

    Using .readSome() you can read piecewise instead of waiting for the input to be finished and then reading everything at once. You can change the text encoding with .encoding.

    Commands

    Run

    let date: String = run("date", "-u")
    @@ -337,28 +363,6 @@
     

     

    When launched from the top level you don’t need to catch any errors, but you still have to use try.

    -

    Streams

    -

    Output

    - -

    main.stdout is for normal output and main.stderror for errors. You can also write to a file:

    -
    main.stdout.print("everything is fine")
    -main.stderror.print("no wait, something went wrong ...")
    -
    -let file = try open(forWriting: path)
    -file.print("something")
    -
    - -

    .write doesn’t add a newline, and you can change the text encoding with .encoding.

    -

    Input

    - -

    Use main.stdin to read from standard input, or you can read from a file:

    -
    let input: String? = main.stdin.readSome() // read what is available, don't wait for end of file 
    -
    -let file = try open(path)
    -let contents: String = file.read() // read everything
    -
    - -

    Using .readSome() you can read piecewise instead of waiting for the input to be finished and then reading everything at once. You can change the text encoding with .encoding.

    The Terminal

    Setup

    @@ -418,7 +422,7 @@ cd SwiftShell diff --git a/undocumented.json b/undocumented.json index 4428491..9d097a9 100644 --- a/undocumented.json +++ b/undocumented.json @@ -23,21 +23,28 @@ }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", - "line": 240, + "line": 174, + "symbol": "RunOutput.error", + "symbol_kind": "source.lang.swift.decl.var.instance", + "warning": "undocumented" + }, + { + "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", + "line": 251, "symbol": "AsyncCommand.stdout", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", - "line": 241, + "line": 252, "symbol": "AsyncCommand.stderror", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Command.swift", - "line": 286, + "line": 306, "symbol": "AsyncCommand.onCompletion(handler:)", "symbol_kind": "source.lang.swift.decl.function.method.instance", "warning": "undocumented" @@ -121,42 +128,42 @@ }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 92, + "line": 93, "symbol": "MainContext", "symbol_kind": "source.lang.swift.decl.class", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 100, + "line": 101, "symbol": "MainContext.env", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 101, + "line": 102, "symbol": "MainContext.stdin", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 102, + "line": 103, "symbol": "MainContext.stdout", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 103, + "line": 104, "symbol": "MainContext.stderror", "symbol_kind": "source.lang.swift.decl.var.instance", "warning": "undocumented" }, { "file": "/Users/karemorstol/Programming/SwiftShell/SwiftShell3/Sources/SwiftShell/Context.swift", - "line": 138, + "line": 139, "symbol": "main", "symbol_kind": "source.lang.swift.decl.var.global", "warning": "undocumented"