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:)
+
+
+ error
+
+ Undocumented
+ +Swift
+public final class RunOutput
+
+
@@ -300,12 +327,88 @@
+
+
+ &&(_:_:)
+
+ 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. + +Swift
+public static func && (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
+
+ 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. + +Swift
+public static func || (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
+
+ the result of the second one if it was run, otherwise the first one.
+ +
+
+
+ lines()
+
+ Split text into lines (as separated by newlines).
+ +Swift
+public func lines() -> [String]
+
+
-
-
- run(bash:file:line:)
+
+
+ run(bash:combineOutput:)
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +
-
-
- runAsync(bash:)
+
+
+ runAsync(bash:file:line:)
Swift
-public func runAsync (bash bashcommand: String) -> AsyncCommand
+ public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
-
-
- run(_:_:file:line:)
+
+
+ run(_:_:combineOutput:)
Runs a command.
-Warning
- will crash if ‘executable’ could not be launched. - -
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +
-
-
- run(bash:file:line:)
+
+
+ run(bash:combineOutput:)
Extension method
@@ -254,7 +254,7 @@
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +
-
-
- runAsync(bash:)
+
+
+ runAsync(bash:file:line:)
Extension method
@@ -304,7 +317,7 @@
Swift
-public func runAsync (bash bashcommand: String) -> AsyncCommand
+ public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
-
-
- run(_:_:file:line:)
+
+
+ run(_:_:combineOutput:)
Extension method
@@ -414,18 +427,12 @@
Runs a command.
-Warning
- will crash if ‘executable’ could not be launched. - -
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +print from Swift’s standard lib
diff --git a/Structs.html b/Structs.html
index 0475024..c6a726d 100644
--- a/Structs.html
+++ b/Structs.html
@@ -117,10 +117,10 @@
open(forWriting:overwrite:encoding:)
Creates a blank CustomContext.
+Creates a blank CustomContext where env and stdin are empty, stdout and stderror discard everything and +currentdirectory is the current working directory.
Creates a new CustomContext from another Context.
+Creates an identical copy of another Context.
+
+
+ error
+
+ Undocumented
+ +Swift
+public final class RunOutput
+
+
@@ -300,12 +327,88 @@
+
+
+ &&(_:_:)
+
+ 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. + +Swift
+public static func && (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
+
+ 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. + +Swift
+public static func || (lhs: RunOutput, rhs: @autoclosure () -> RunOutput) -> RunOutput
+
+ the result of the second one if it was run, otherwise the first one.
+ +
+
+
+ lines()
+
+ Split text into lines (as separated by newlines).
+ +Swift
+public func lines() -> [String]
+
+
-
-
- run(bash:file:line:)
+
+
+ run(bash:combineOutput:)
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +
-
-
- runAsync(bash:)
+
+
+ runAsync(bash:file:line:)
Swift
-public func runAsync (bash bashcommand: String) -> AsyncCommand
+ public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
-
-
- run(_:_:file:line:)
+
+
+ run(_:_:combineOutput:)
Runs a command.
-Warning
- will crash if ‘executable’ could not be launched. - -
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +
-
-
- run(bash:file:line:)
+
+
+ run(bash:combineOutput:)
Extension method
@@ -254,7 +254,7 @@
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +
-
-
- runAsync(bash:)
+
+
+ runAsync(bash:file:line:)
Extension method
@@ -304,7 +317,7 @@
Swift
-public func runAsync (bash bashcommand: String) -> AsyncCommand
+ public func runAsync (bash bashcommand: String, file: String = #file, line: Int = #line) -> AsyncCommand
-
-
- run(_:_:file:line:)
+
+
+ run(_:_:combineOutput:)
Extension method
@@ -414,18 +427,12 @@
Runs a command.
-Warning
- will crash if ‘executable’ could not be launched. - -
+ combineOutput
+
+ if true then stdout and stderror go to the same stream. Default is false.
+ +print from Swift’s standard lib
diff --git a/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs.html b/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs.html
index 0475024..c6a726d 100644
--- a/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs.html
+++ b/docsets/SwiftShell.docset/Contents/Resources/Documents/Structs.html
@@ -117,10 +117,10 @@
open(forWriting:overwrite:encoding:)
Creates a blank CustomContext.
+Creates a blank CustomContext where env and stdin are empty, stdout and stderror discard everything and +currentdirectory is the current working directory.
Creates a new CustomContext from another Context.
+Creates an identical copy of another Context.
Swift 3 | Swift 2
+
+
+
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:)
- run(_:_:file:line:)
+ run(_:_:combineOutput:)
- run(bash:file:line:)
+ run(bash:combineOutput:)
runAndPrint(_:_:)
@@ -132,7 +132,7 @@
runAsync(_:_:file:line:)
- runAsync(bash:)
+ runAsync(bash:file:line:)
streams()
@@ -185,6 +185,10 @@
Swift 3 | Swift 2
+
+
+
+
SwiftShell
@@ -207,6 +211,7 @@
Example scripts
+- [
- Move files to the trash
- Combine markdown files and convert to HTML (runs a shell command in the middle of a method chain)
@@ -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"