Repository navigation
Add subcommands - #182
Add subcommands#182fpseverino wants to merge 27 commits into
Conversation
| var other: [String] | ||
|
|
||
| mutating func run() async throws { | ||
| print("🚧 Work in progress 🚧") |
There was a problem hiding this comment.
@ptoffy should already have a fix ready for this
0xTim
left a comment
There was a problem hiding this comment.
Let's put each command into it's own file.
Also, just noticed that we should make secret configuration options as secrets
|
OK, I think I’ve got a clearer picture now. The Swift Configuration guide on interoperability with ArgumentParser covers two scenarios:
The guide also states that it is possible to combine the two approaches if necessary, and this is precisely our situation, because we define the arguments that Vapor needs in the My issue with combining the two approaches from the guide is that it's much more verbose and AFAICT technically the same as the code I wrote originally. It would be also be harder to maintain. Here's the diff where I apply the Swift Configuration guidelines to my original code: struct Serve: AsyncParsableCommand {
@Option var hostname: String?
@Option var port: Int?
@Option var bind: String?
@Option var socketPath: String?
@Argument(parsing: .allUnrecognized, help: .private)
var configArguments: [String] = []
mutating func run() async throws {
+ var values: [AbsoluteConfigKey: ConfigValue] = [:]
+ if let hostname { values["hostname"] = .init(.string(hostname), isSecret: false) }
+ if let port { values["port"] = .init(.int(port), isSecret: false) }
+ if let bind { values["bind"] = .init(.string(bind), isSecret: false) }
+ if let socketPath { values["socketPath"] = .init(.string(socketPath), isSecret: false) }
let config = ConfigReader(providers: [
+ InMemoryProvider(name: "arguments", values: values),
- CommandLineArgumentsProvider(),
+ CommandLineArgumentsProvider(arguments: ["serve"] + configArguments),
EnvironmentVariablesProvider(),
])
}
}The PR right now uses my version. I will ask the maintainers of Swift Configuration if my code is actually technically the same as the two approaches combined. |
@0xTim I have received confirmation that this approach is valid |
serve,routesandmigratesubcommands (the latter is WIP) from Vapor 4 using Swift Argument Parser