console-kit icon indicating copy to clipboard operation
console-kit copied to clipboard

Modify the`AsyncCommand` implementation `Command` to support asynchronous methods through `EventLoopPromise`, so as to support the `Command` of vapor to support asynchronous methods

Open josercc opened this issue 3 years ago • 0 comments

@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
final class TestCommand: AsyncCommand {
    struct Signature: CommandSignature {
        @Argument(name: "foo", help: """
        A foo is required
        An error will occur if none exists
        """)
        var foo: String

        @Option(name: "bar", short: "b", help: """
        Add a bar if you so desire
        Try passing it
        """)
        var bar: String?

        @Flag(name: "baz", short: "B", help: """
        Add a baz if you so desire
        It's just a flag
        """)
        var baz: Bool

        init() { }
    }

    let help: String = "This is a test command"

    func run(using context: CommandContext, signature: Signature) async throws {
        XCTAssertEqual(signature.$foo.name, "foo")
        XCTAssertEqual(signature.$bar.name, "bar")
        XCTAssertEqual(signature.$baz.name, "baz")
        context.console.output("Foo: \(signature.foo) Bar: \(signature.bar ?? "nil")".consoleText(.info))
    }
}

Because the bottom layer of AsyncCommand implements Command, I deleted some unnecessary classes

josercc avatar Jun 23 '22 01:06 josercc