CommandArgument

public struct CommandArgument

A required argument for a Command.

exec command <arg>

Used by Command.arguments.

struct CowsayCommand: Command {
    var arguments: [CommandArgument] {
        return [.argument(name: "message")]
    }
    ...
}

Fetch arguments using CommandContext.argument(_:)

struct CowsayCommand: Command {
    ...
    func run(using context: CommandContext) throws -> Future<Void> {
        let message = try context.argument("message")
        ...
    }
    ...
}

See Command for more information.

  • Creates a new CommandArgument.

     let arguments: [CommandArgument] = [.argument(name: "message")]
    

    Declaration

    Swift

    public static func argument(name: String, help: [String] = []) -> CommandArgument

    Parameters

    name

    This argument’s unique name. Use this to fetch the argument from the CommandContext.

  • The argument’s unique name.

    Declaration

    Swift

    public let name: String
  • The arguments’s help text when --help is passed.

    Declaration

    Swift

    public let help: [String]