CommandConfig

public struct CommandConfig: Service

Configures commands for a service container.

var commandConfig = CommandConfig.default()
/// You can register command types that will be lazily created
commandConfig.use(FooCommand.self, as: "foo")
/// You can also register pre-initialized instances of a command
commandConfig.use(barCommand, as: "bar")
services.register(commandConfig)
  • A lazily initialized CommandRunnable.

    Declaration

    Swift

    public typealias LazyCommand = (Container) throws -> CommandRunnable
  • Create a new CommandConfig.

    Declaration

    Swift

    public init()
  • Adds a Command instance to the config.

    var commandConfig = CommandConfig.default()
    commandConfig.use(barCommand, as: "bar")
    services.register(commandConfig)
    

    Declaration

    Swift

    public mutating func use(_ command: CommandRunnable, as name: String, isDefault: Bool = false)

    Parameters

    command

    Some CommandRunnable. This type will be requested from the service container later.

    name

    A unique name for running this command.

    isDefault

    If true, this command will be set as the default command to run when none other are specified. Setting this overrides any previous default commands.

  • Adds a CommandRunnable type to the config. This type will be lazily initialized later using a Container.

    var commandConfig = CommandConfig.default()
    commandConfig.use(FooCommand.self, as: "foo")
    services.register(commandConfig)
    

    Declaration

    Swift

    public mutating func use<R>(_ command: R.Type, as name: String, isDefault: Bool = false) where R: CommandRunnable

    Parameters

    command

    Type of some Command. This type will be requested from the service container later.

    name

    A unique name for running this command.

    isDefault

    If true, this command will be set as the default command to run when none other are specified. Setting this overrides any previous default commands.

  • Resolves the configured commands to a ConfiguredCommands struct.

    Throws

    Errors creating the lazy commands from the container.

    Declaration

    Swift

    public func resolve(for container: Container) throws -> Commands

    Parameters

    container

    Container to use for creating lazily initialized commands.

    Return Value

    Commands struct which contains initialized commands.