Skip to content

Add return self to methods with completion closure that already had… #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions SwiftSH/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ open class SSHChannel<T: RawLibrary>: SSHSession<T> {
// MARK: - Terminal

public func setTerminalSize(width: UInt, height: UInt) -> Self {
self.setTerminalSize(width: width, height: height, completion: nil)

return self
return self.setTerminalSize(width: width, height: height, completion: nil)
}

public func setTerminalSize(width: UInt, height: UInt, completion: SSHCompletionBlock?) {
public func setTerminalSize(width: UInt, height: UInt, completion: SSHCompletionBlock?) -> Self {
self.queue.async(completion: completion) {
guard let terminal = self.terminal else {
throw SSHError.badUse
Expand All @@ -140,6 +138,7 @@ open class SSHChannel<T: RawLibrary>: SSHSession<T> {
self.terminal = resizedTerminal
}
}
return self
}

}
17 changes: 8 additions & 9 deletions SwiftSH/SCP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,34 @@ public class SCPSession<T: RawLibrary>: SSHChannel<T> {
// MARK: - Download

public func download(_ from: String, to path: String) -> Self {
self.download(from, to: path, completion: nil)

return self
return self.download(from, to: path, completion: nil)
}

public func download(_ from: String, to path: String, completion: SSHCompletionBlock?) {
@discardableResult
public func download(_ from: String, to path: String, completion: SSHCompletionBlock?) -> Self {
if let stream = OutputStream(toFileAtPath: path, append: false) {
self.download(from, to: stream, completion: completion)
} else if let completion = completion {
self.queue.callbackQueue.async {
completion(SSHError.SCP.invalidPath)
}
}
return self
}


public func download(_ from: String, to stream: OutputStream) -> Self {
self.download(from, to: stream, completion: nil)

return self
return self.download(from, to: stream, completion: nil)
}

public func download(_ from: String, to stream: OutputStream, completion: SSHCompletionBlock?) {
@discardableResult
public func download(_ from: String, to stream: OutputStream, completion: SSHCompletionBlock?) -> Self {
self.queue.async(completion: completion) {
stream.open()
defer {
stream.close()
}
}
return self
}

public func download(_ from: String, completion: @escaping ((Data?, Error?) -> Void)) {
Expand Down
16 changes: 8 additions & 8 deletions SwiftSH/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ open class SSHSession<T: RawLibrary> {
}

public func connect() -> Self {
self.connect(nil)

return self
return connect(nil)
}

public func connect(_ completion: SSHCompletionBlock?) {
@discardableResult
public func connect(_ completion: SSHCompletionBlock?) -> Self {
self.queue.async(completion: completion) {
defer {
if !self.connected {
Expand Down Expand Up @@ -220,6 +219,7 @@ open class SSHSession<T: RawLibrary> {
}
self.log.debug("Fingerprint is \(self.fingerprint)")
}
return self
}

public func disconnect(_ completion: (() -> ())?) {
Expand Down Expand Up @@ -276,12 +276,11 @@ open class SSHSession<T: RawLibrary> {
}

public func authenticate(_ challenge: AuthenticationChallenge?) -> Self {
self.authenticate(challenge, completion: nil)

return self
return self.authenticate(challenge, completion: nil)
}

public func authenticate(_ challenge: AuthenticationChallenge?, completion: SSHCompletionBlock?) {
@discardableResult
public func authenticate(_ challenge: AuthenticationChallenge?, completion: SSHCompletionBlock?) -> Self {
self.queue.async(completion: completion) {
guard let challenge = challenge, !self.authenticated else {
return
Expand Down Expand Up @@ -324,6 +323,7 @@ open class SSHSession<T: RawLibrary> {
try self.session.authenticateByPublicKeyFromMemory(username, password: password, publicKey: publicKey, privateKey: privateKey)
}
}
return self
}

public func checkFingerprint(_ callback: @escaping ([FingerprintHashType: String]) -> Bool) -> Self {
Expand Down
28 changes: 15 additions & 13 deletions SwiftSH/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public class SSHShell<T: RawLibrary>: SSHChannel<T> {
// MARK: - Open/Close

public func open() -> Self {
self.open(nil)

return self
return open(nil)
}

public func open(_ completion: SSHCompletionBlock?) {
@discardableResult
public func open(_ completion: SSHCompletionBlock?) -> Self {
self.queue.async(completion: completion) {
// Open the channel
try super.open()
Expand Down Expand Up @@ -223,6 +222,8 @@ public class SSHShell<T: RawLibrary>: SSHChannel<T> {

self.log.debug("Shell opened successfully")
}

return self
}

public func close(_ completion: (() -> ())?) {
Expand Down Expand Up @@ -267,12 +268,11 @@ public class SSHShell<T: RawLibrary>: SSHChannel<T> {
// MARK: - Write

public func write(_ data: Data) -> Self {
self.write(data, completion: nil)

return self
return self.write(data, completion: nil)
}

public func write(_ data: Data, completion: ((Error?) -> Void)?) {
@discardableResult
public func write(_ data: Data, completion: ((Error?) -> Void)?) -> Self {
self.queue.async {
// Insert the message in the message queue
let message = Message(data: data, callback: completion)
Expand All @@ -284,25 +284,27 @@ public class SSHShell<T: RawLibrary>: SSHChannel<T> {
writeSource.resume()
}
}
return self
}

public func write(_ command: String) -> Self {
self.write(command, completion: nil)

return self
return self.write(command, completion: nil)
}

public func write(_ command: String, completion: ((Error?) -> Void)?) {
@discardableResult
public func write(_ command: String, completion: ((Error?) -> Void)?) -> Self {
guard let data = command.data(using: .utf8) else {
if let completion = completion {
self.queue.callbackQueue.async {
completion(SSHError.invalid)
}
}
return
return self
}

self.write(data, completion: completion)

return self
}
}

Expand Down