@@ -26,28 +26,17 @@ struct Unlink: SwiftlyCommand {
2626 }
2727
2828 mutating func run( _ ctx: SwiftlyCoreContext ) async throws {
29- try await validatedConfig ( ctx)
29+ try await validateConfig ( ctx)
3030
3131 var pathChanged = false
32- if let proxyTo = try ? await Swiftly . currentPlatform. findSwiftlyBin ( ctx) {
33- let swiftlyBinDir = Swiftly . currentPlatform. swiftlyBinDir ( ctx)
34- let swiftlyBinDirContents = ( try ? await fs. ls ( atPath: swiftlyBinDir) ) ?? [ String] ( )
35-
36- var existingProxies = [ String] ( )
37- for bin in swiftlyBinDirContents {
38- let linkTarget = try ? await fs. readlink ( atPath: swiftlyBinDir / bin)
39- if linkTarget == proxyTo {
40- existingProxies. append ( bin)
41- }
42- }
32+ let existingProxies = try await symlinkedProxies ( ctx)
4333
44- for p in existingProxies {
45- let proxy = Swiftly . currentPlatform. swiftlyBinDir ( ctx) / p
34+ for p in existingProxies {
35+ let proxy = Swiftly . currentPlatform. swiftlyBinDir ( ctx) / p
4636
47- if try await fs. exists ( atPath: proxy) {
48- try await fs. remove ( atPath: proxy)
49- pathChanged = true
50- }
37+ if try await fs. exists ( atPath: proxy) {
38+ try await fs. remove ( atPath: proxy)
39+ pathChanged = true
5140 }
5241 }
5342
@@ -57,3 +46,27 @@ struct Unlink: SwiftlyCommand {
5746 }
5847 }
5948}
49+
50+ func symlinkedProxies( _ ctx: SwiftlyCoreContext ) async throws -> [ String ] {
51+ if let proxyTo = try ? await Swiftly . currentPlatform. findSwiftlyBin ( ctx) {
52+ let swiftlyBinDir = Swiftly . currentPlatform. swiftlyBinDir ( ctx)
53+ let swiftlyBinDirContents = ( try ? await fs. ls ( atPath: swiftlyBinDir) ) ?? [ String] ( )
54+ var proxies = [ String] ( )
55+ for bin in swiftlyBinDirContents {
56+ let linkTarget = try ? await fs. readlink ( atPath: swiftlyBinDir / bin)
57+ if linkTarget == proxyTo {
58+ proxies. append ( bin)
59+ }
60+ }
61+ return proxies
62+ }
63+ return [ ]
64+ }
65+
66+ extension SwiftlyCommand {
67+ func valitateLinked( _ ctx: SwiftlyCoreContext ) async throws {
68+ if try await symlinkedProxies ( ctx) . isEmpty {
69+ await ctx. print ( Messages . currentlyUnlinked)
70+ }
71+ }
72+ }
0 commit comments