From 8b0d696e46aecf304d60fe25c6828fab4a7fca92 Mon Sep 17 00:00:00 2001 From: Vatsal Manot Date: Sun, 24 Nov 2024 02:26:13 +0530 Subject: [PATCH] Update package --- Package.swift | 31 ++++++++++--------- .../Intramodular/AnyCommandLineTool.swift | 20 +++++++++++- Sources/Merge/module.swift | 1 - .../Intramodular/Process+sh.swift | 10 ++++++ .../Intramodular/Process-Initializers.swift | 0 .../{Shell => ShellScripting}/module.swift | 0 Tests/ProcessInitializerTests.swift | 2 +- 7 files changed, 46 insertions(+), 18 deletions(-) rename Sources/{Shell => ShellScripting}/Intramodular/Process+sh.swift (97%) rename Sources/{Shell => ShellScripting}/Intramodular/Process-Initializers.swift (100%) rename Sources/{Shell => ShellScripting}/module.swift (100%) diff --git a/Package.swift b/Package.swift index fa4c105..f9a662a 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,7 @@ var package = Package( name: "Merge", targets: [ "CommandLineToolSupport", - "Shell", + "ShellScripting", "SwiftDI", "Merge" ] @@ -36,34 +36,35 @@ var package = Package( ] ), .target( - name: "CommandLineToolSupport", + name: "Merge", dependencies: [ "Swallow", + .product(name: "SwallowMacrosClient", package: "Swallow"), + "SwiftDI" ], - path: "Sources/CommandLineToolSupport", + path: "Sources/Merge", swiftSettings: [ .enableExperimentalFeature("AccessLevelOnImport") ] ), .target( - name: "Merge", + name: "ShellScripting", dependencies: [ - "CommandLineToolSupport", - "Swallow", - .product(name: "SwallowMacrosClient", package: "Swallow"), - "SwiftDI" + "Merge" ], - path: "Sources/Merge", + path: "Sources/ShellScripting", swiftSettings: [ .enableExperimentalFeature("AccessLevelOnImport") ] ), .target( - name: "Shell", + name: "CommandLineToolSupport", dependencies: [ - "Merge" + "Merge", + "ShellScripting", + "Swallow", ], - path: "Sources/Shell", + path: "Sources/CommandLineToolSupport", swiftSettings: [ .enableExperimentalFeature("AccessLevelOnImport") ] @@ -71,11 +72,11 @@ var package = Package( .testTarget( name: "MergeTests", dependencies: [ + "CommandLineToolSupport", "Merge", - "Shell", + "ShellScripting", ], path: "Tests" ) - ], - swiftLanguageVersions: [.v5] + ] ) diff --git a/Sources/CommandLineToolSupport/Intramodular/AnyCommandLineTool.swift b/Sources/CommandLineToolSupport/Intramodular/AnyCommandLineTool.swift index b4ac2f6..4f1755e 100644 --- a/Sources/CommandLineToolSupport/Intramodular/AnyCommandLineTool.swift +++ b/Sources/CommandLineToolSupport/Intramodular/AnyCommandLineTool.swift @@ -3,12 +3,30 @@ // import Foundation -import Swift +import Merge open class AnyCommandLineTool { public var environmentVariables: [String: any CLT.EnvironmentVariableValue] = [:] + public var currentDirectoryURL: URL? = nil public init() { } } + +extension AnyCommandLineTool { + @discardableResult + public func withUnsafeSystemShell( + perform operation: (SystemShell) async throws -> R + ) async throws -> R { + let shell = SystemShell( + environment: environmentVariables.mapValues({ String(describing: $0) }), + currentDirectoryURL: currentDirectoryURL, + options: [._forwardStdoutStderr] + ) + + let result: R = try await operation(shell) + + return result + } +} diff --git a/Sources/Merge/module.swift b/Sources/Merge/module.swift index aa50d08..a84ee85 100644 --- a/Sources/Merge/module.swift +++ b/Sources/Merge/module.swift @@ -2,7 +2,6 @@ // Copyright (c) Vatsal Manot // -@_exported import CommandLineToolSupport @_exported import Diagnostics @_exported import Combine @_exported import Swallow diff --git a/Sources/Shell/Intramodular/Process+sh.swift b/Sources/ShellScripting/Intramodular/Process+sh.swift similarity index 97% rename from Sources/Shell/Intramodular/Process+sh.swift rename to Sources/ShellScripting/Intramodular/Process+sh.swift index 32c6416..fe00d81 100644 --- a/Sources/Shell/Intramodular/Process+sh.swift +++ b/Sources/ShellScripting/Intramodular/Process+sh.swift @@ -9,6 +9,7 @@ import Merge internal import Swallow import Swift +@available(*, deprecated) public func shq( _ cmd: String, arguments: [Process.ArgumentLiteral] = [], @@ -24,6 +25,7 @@ public func shq( ._runSynchronously() } +@available(*, deprecated) @_disfavoredOverload public func shq( _ cmd: String, @@ -39,6 +41,7 @@ public func shq( ) } +@available(*, deprecated) public func shq( _ cmd: String, arguments: [String], @@ -54,6 +57,7 @@ public func shq( .validate() } +@available(*, deprecated) public func shq( _ cmd: String, arguments: [Process.ArgumentLiteral] = [], @@ -69,6 +73,7 @@ public func shq( ._runAsynchronously() } +@available(*, deprecated) @_disfavoredOverload public func shq( _ cmd: String, @@ -84,6 +89,7 @@ public func shq( ) } +@available(*, deprecated) public func shq( _ cmd: String, arguments: [String], @@ -99,6 +105,7 @@ public func shq( .validate() } +@available(*, deprecated) public func shq( _ type: D.Type, decodedBy jsonDecoder: JSONDecoder = .init(), @@ -116,6 +123,7 @@ public func shq( .decode(type, using: jsonDecoder) } +@available(*, deprecated) public func shq( _ type: D.Type, decodedBy jsonDecoder: JSONDecoder = .init(), @@ -132,6 +140,7 @@ public func shq( return try await process._runAsynchronously().stdout.decode(type, using: jsonDecoder) } +@available(*, deprecated) @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) public func shq( _ sink: Process.StandardOutputSink, @@ -148,6 +157,7 @@ public func shq( try process._runSynchronouslyRedirectingAllOutput(to: sink) } +@available(*, deprecated) @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) public func shq( _ sink: Process.StandardOutputSink, diff --git a/Sources/Shell/Intramodular/Process-Initializers.swift b/Sources/ShellScripting/Intramodular/Process-Initializers.swift similarity index 100% rename from Sources/Shell/Intramodular/Process-Initializers.swift rename to Sources/ShellScripting/Intramodular/Process-Initializers.swift diff --git a/Sources/Shell/module.swift b/Sources/ShellScripting/module.swift similarity index 100% rename from Sources/Shell/module.swift rename to Sources/ShellScripting/module.swift diff --git a/Tests/ProcessInitializerTests.swift b/Tests/ProcessInitializerTests.swift index 8278839..4b048e2 100644 --- a/Tests/ProcessInitializerTests.swift +++ b/Tests/ProcessInitializerTests.swift @@ -2,7 +2,7 @@ // Copyright (c) Vatsal Manot // -@testable import Shell +@testable import ShellScripting import XCTest class ShellProcessTests: XCTestCase {