swift-service-lifecycle icon indicating copy to clipboard operation
swift-service-lifecycle copied to clipboard

Future idea: if @main lands and SPM supports it, offer an "entry point"?

Open ktoso opened this issue 4 years ago • 6 comments

The ongoing pitch https://forums.swift.org/t/main-type-based-program-execution/34624 introduces @main define-able entry points.

It is also aimed for libraries to provide their patterns / entry points.

It currently will NOT work with Swift Package Manager... but if we were able to make it work there, we could offer APIs similar to

@main 
struct MyService: ServiceLifecycleMain {
// or struct MyService: ServiceBootstrapMain {

    // some command line things, using ParsableCommand
    @Argument(help: "What port to bind to")
    var port: [Int]

    // NOT ACTUAL API; not through through how it'd look like exactly,
    // but we'd allow registering the phases here?
    func configurePhases/Tasks() {}

    func onShutdown(error: [String: Error]?) {}
}

ktoso avatar Apr 07 '20 06:04 ktoso

thats a good idea once the feature is available to us 👍

tomerd avatar Apr 08 '20 01:04 tomerd

@ktoso & @tomerd This seems like a great idea which should now be possible through .executableTarget (5.4) 👍 I like the interplay of ArgumentParser and Lifecycle. Though getting this example to work would require Lifecycle to depend on ArgumentParser. Is that something we'd be open to doing?

slashmo avatar May 06 '21 23:05 slashmo

I think this could be good, but as a separate, optional target, kind of like how we do lifecycle + nio

tomerd avatar May 06 '21 23:05 tomerd

we could/should probably also just provide a static main that calls start etc that folks can use in @main setups

tomerd avatar May 06 '21 23:05 tomerd

separate target sounds good :)

ktoso avatar May 06 '21 23:05 ktoso

Sounds good 👍 I'll poke around a bit.

slashmo avatar May 07 '21 14:05 slashmo

This can be closed given the upcoming 2.0 revision which handles much more :)

ktoso avatar Aug 23 '23 10:08 ktoso