Disable default subcommand, enable version flag

This commit is contained in:
Max Desiatov 2020-06-22 13:11:20 +01:00
parent bd9cb4c2cb
commit b3b1144f59
No known key found for this signature in database
GPG Key ID: FE08EBF9CF58CBA2
5 changed files with 19 additions and 9 deletions

10
.vscode/tasks.json vendored
View File

@ -3,6 +3,16 @@
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build and run",
"type": "shell",
"command": "swift build && cd TestApp && ../.build/debug/carton"
},
{
"label": "build and version",
"type": "shell",
"command": "swift build && cd TestApp && ../.build/debug/carton --version"
},
{
"label": "build and run dev",
"type": "shell",

View File

@ -29,13 +29,13 @@ instead of Foundation's `URLSession` for dependency downloads.
# 0.1.0 (16 June 2020)
Since SwiftPM doesn't always build an executable target even if one is present without
an explicit `--product` flag, the `dev` command now requires the presence of an executable
target in your `Package.swift`. Use the new `--product` flag instead of `--target` to
an explicit `--product` option, the `dev` command now requires the presence of an executable
target in your `Package.swift`. Use the new `--product` option instead of `--target` to
disambiguate between multiple executable targets.
# 0.0.5 (16 June 2020)
Pass `--target` flag to `swift build` when running the `dev` command.
Pass `--target` option to `swift build` when running the `dev` command.
# 0.0.4 (16 June 2020)

View File

@ -17,7 +17,7 @@ import ArgumentParser
struct Carton: ParsableCommand {
static var configuration = CommandConfiguration(
abstract: "📦 Watcher, bundler, and test runner for your SwiftWasm apps.",
subcommands: [Dev.self, Test.self, Bundle.self],
defaultSubcommand: Dev.self
version: "0.1.5",
subcommands: [Dev.self, Test.self, Bundle.self]
)
}

View File

@ -61,7 +61,7 @@ struct Dev: ParsableCommand {
try dependency.check(on: localFileSystem, terminal)
let swiftPath = try localFileSystem.inferSwiftPath(terminal)
guard let product = try Package(with: swiftPath, terminal)
.inferDevProduct(with: swiftPath, flag: product, terminal)
.inferDevProduct(with: swiftPath, option: product, terminal)
else { return }
let binPath = try localFileSystem.inferBinPath(swiftPath: swiftPath)

View File

@ -33,14 +33,14 @@ struct Package: Codable {
func inferDevProduct(
with swiftPath: String,
flag: String?,
option: String?,
_ terminal: TerminalController
) -> String? {
var candidateProducts = products
.filter { $0.type.library == nil }
.map(\.name)
if let product = flag {
if let product = option {
candidateProducts = candidateProducts.filter { $0 == product }
guard candidateProducts.count == 1 else {
@ -59,7 +59,7 @@ struct Package: Codable {
terminal.write("Failed to disambiguate the development product\n", inColor: .red)
if candidateProducts.count > 1 {
terminal.write("Pass one of \(candidateProducts) to the --product flag\n", inColor: .red)
terminal.write("Pass one of \(candidateProducts) to the --product option\n", inColor: .red)
} else {
terminal.write(
"Make sure there's at least one executable product in your Package.swift\n",