Command
struct Command : CustomStringConvertible
The command which to be executed.
This struct holds all settings for command execution and can be created througt
CLI.run(_:_:executor:)
functions or directly.
CLI.run("echo -n", "Hi!")
// is equivalent to
Command(["echo", "-n", "Hi!"]).execute()
Note
Command
is more complex than simple run
function.
You can specify command working directory or environment variables.
-
The command executor.
Declaration
Swift
public let executor: CommandExecutor
-
The path to working diretory for current command.
Declaration
Swift
public let workingDirectory: String
-
The environment for the command. If this is
nil
, the environment is inherited from the current process.Declaration
Swift
public let environment: [String : String]?
-
A textual representation of command wit all arguments.
Declaration
Swift
public var description: String { get }
-
Creates an instance of command.
Note
The parameters workingDirectory and environment may not be supported in some executors.Declaration
Swift
public init( _ arguments: [String], executor: CommandExecutor = .default, workingDirectory: String = FileManager.default.currentDirectoryPath, environment: [String: String]? = nil )
Parameters
arguments
The array with all command parts.
executor
The command executor which will be used to execute command.
workingDirectory
The current working directory for executed command.
environment
The environment variables for executed command.
-
Execute command with given executor.
Declaration
Swift
@discardableResult public func execute() throws -> String
Return Value
The command execution result.