Skip to content

Commit

Permalink
which cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Jul 14, 2019
1 parent 697aa73 commit 13e1f32
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/CommandKit/Commands/File+Cmd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ extension Cmd {
return shell.cd(path: path)
}

/// Return a command path if exists
/// - Parameter command: Command
public func which(_ command: String) -> EventLoopFuture<String> {
return shell.run(bash: "which \(command)").trimMap()
}

/// Check is command exists
/// - Parameter command: Command
public func exists(command: String) -> EventLoopFuture<Bool> {
return shell.cmd.which(command).map { !$0.isEmpty }.recover { _ in false }
}

/// Return content of a file as a string
/// - Parameter path: Path to file
public func cat(path: String) -> EventLoopFuture<String> {
Expand Down

0 comments on commit 13e1f32

Please sign in to comment.