Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 13e1f32

Browse files
committed
which cmd
1 parent 697aa73 commit 13e1f32

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Sources/CommandKit/Commands/File+Cmd.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ extension Cmd {
2323
return shell.cd(path: path)
2424
}
2525

26+
/// Return a command path if exists
27+
/// - Parameter command: Command
28+
public func which(_ command: String) -> EventLoopFuture<String> {
29+
return shell.run(bash: "which \(command)").trimMap()
30+
}
31+
32+
/// Check is command exists
33+
/// - Parameter command: Command
34+
public func exists(command: String) -> EventLoopFuture<Bool> {
35+
return shell.cmd.which(command).map { !$0.isEmpty }.recover { _ in false }
36+
}
37+
2638
/// Return content of a file as a string
2739
/// - Parameter path: Path to file
2840
public func cat(path: String) -> EventLoopFuture<String> {

0 commit comments

Comments
 (0)