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
argumentsThe array with all command parts.
executorThe command executor which will be used to execute command.
workingDirectoryThe current working directory for executed command.
environmentThe environment variables for executed command.
-
Execute command with given executor.
Declaration
Swift
@discardableResult public func execute() throws -> StringReturn Value
The command execution result.
View on GitHub
Command Structure Reference