CommandArgumentConvertible

public protocol CommandArgumentConvertible

Marks a type as CommandArgumentConvertible.

These types can be created from one or more arguments passed into a command.

  • The type arguments will be resolved to.

    Defaults to Self

    Declaration

    Swift

    associatedtype ResolvedArgument = Self
  • typedName Default implementation

    Name used in descriptions.

    Int.typedName // "Int"
    

    Default Implementation

    Declaration

    Swift

    static var typedName: String { get }
  • Attempts to resolve an argument from the provided string.

    Throws

    CommandError.UnableToConvertArgument when ResolvedArgument can not be created from argument CommandError.ArgumentNotFound when no argument is found

    Declaration

    Swift

    static func resolveArgument(_ argument: String, on event: CommandEvent) throws -> ResolvedArgument

    Parameters

    argument

    String taken from the message body.

    event

    The CommandEvent this argument should be resolved for.

    Return Value

    The resolved argument

  • resolveArgument(_:arg:on:) Default implementation

    Attempts to resolve an argument from the provided string.

    A default implementation is provided. The default implementation will throw CommandArgument.ArgumentNotFound when nil is passed in.

    Throws

    CommandError.UnableToConvertArgument when ResolvedArgument can not be created from argument CommandError.ArgumentNotFound when no argument is found

    Default Implementation

    Declaration

    Swift

    static func resolveArgument(_ argument: String?, arg: CommandArgument, on event: CommandEvent) throws -> ResolvedArgument

    Parameters

    argument

    String taken from the message body.

    event

    The CommandEvent this argument should be resolved for.

    Return Value

    The resolved argument