From b274d58764c1dadcf8767f63a6050d32a4d9155c Mon Sep 17 00:00:00 2001 From: gibachan Date: Sat, 1 Nov 2025 21:55:57 +0900 Subject: [PATCH] Fix `swiftly run -h` to show help message --- Sources/Swiftly/Run.swift | 2 +- Tests/SwiftlyTests/RunTests.swift | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Sources/Swiftly/Run.swift b/Sources/Swiftly/Run.swift index 21c1bb2c..9805e19d 100644 --- a/Sources/Swiftly/Run.swift +++ b/Sources/Swiftly/Run.swift @@ -63,7 +63,7 @@ struct Run: SwiftlyCommand { var config = try await Config.load(ctx) // Handle the specific case where help is requested of the run subcommand - if command == ["--help"] { + if command == ["--help"] || command == ["-h"] { throw CleanExit.helpRequest(self) } diff --git a/Tests/SwiftlyTests/RunTests.swift b/Tests/SwiftlyTests/RunTests.swift index 09546e18..4264c0d4 100644 --- a/Tests/SwiftlyTests/RunTests.swift +++ b/Tests/SwiftlyTests/RunTests.swift @@ -1,3 +1,4 @@ +import ArgumentParser import Foundation @testable import Swiftly @testable import SwiftlyCore @@ -84,4 +85,23 @@ import Testing #expect(["swift", "build"] == command) #expect(nil == selector) } + + /// Tests the help functionality of the `run` command + @Test(.testHomeMockedToolchain()) func runHelp() async throws { + // Test --help is handled correctly + do { + try await SwiftlyTests.runCommand(Run.self, ["run", "--help"]) + #expect(false) + } catch { + #expect(error is CleanExit) + } + + // Test -h is handled correctly + do { + try await SwiftlyTests.runCommand(Run.self, ["run", "-h"]) + #expect(false) + } catch { + #expect(error is CleanExit) + } + } }