Skip to content

Commit 85c49df

Browse files
committed
Print message to reload shell
1 parent 6862cb7 commit 85c49df

File tree

6 files changed

+40
-49
lines changed

6 files changed

+40
-49
lines changed

Sources/Swiftly/Init.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -272,27 +272,11 @@ struct Init: SwiftlyCommand {
272272

273273
// Fish doesn't have path caching, so this might only be needed for bash/zsh
274274
if pathChanged && !quietShellFollowup && !shell.hasSuffix("fish") {
275-
await ctx.print("""
276-
Your shell caches items on your path for better performance. Swiftly has added
277-
items to your path that may not get picked up right away. You can update your
278-
shell's environment by running
279-
280-
hash -r
281-
282-
or restarting your shell.
283-
284-
""")
275+
await ctx.print(Messages.refreshShell)
285276
}
286277

287278
if let postInstall {
288-
await ctx.print("""
289-
There are some dependencies that should be installed before using this toolchain.
290-
You can run the following script as the system administrator (e.g. root) to prepare
291-
your system:
292-
293-
\(postInstall)
294-
295-
""")
279+
await ctx.print(Messages.postInstall(postInstall))
296280
}
297281
}
298282
}

Sources/Swiftly/Install.swift

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,37 +106,20 @@ struct Install: SwiftlyCommand {
106106

107107
// Fish doesn't cache its path, so this instruction is not necessary.
108108
if pathChanged && !shell.hasSuffix("fish") {
109-
await ctx.print(
110-
"""
111-
NOTE: Swiftly has updated some elements in your path and your shell may not yet be
112-
aware of the changes. You can update your shell's environment by running
113-
114-
hash -r
115-
116-
or restarting your shell.
117-
118-
""")
109+
await ctx.print(Messages.refreshShell)
119110
}
120111

121112
if let postInstallScript {
122113
guard let postInstallFile = self.postInstallFile else {
123-
throw SwiftlyError(
124-
message: """
125-
126-
There are some dependencies that should be installed before using this toolchain.
127-
You can run the following script as the system administrator (e.g. root) to prepare
128-
your system:
129-
130-
\(postInstallScript)
131-
""")
114+
throw SwiftlyError(message: Messages.postInstall(postInstallScript))
132115
}
133116

134117
try Data(postInstallScript.utf8).write(
135118
to: URL(fileURLWithPath: postInstallFile), options: .atomic
136119
)
137120
}
138-
}
139-
121+
}
122+
140123
public static func setupProxies(
141124
_ ctx: SwiftlyCoreContext,
142125
version: ToolchainVersion,

Sources/Swiftly/Link.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ struct Link: SwiftlyCommand {
3232
config: &config
3333
)
3434

35-
let _ = try await Install.setupProxies(
35+
let pathChanged = try await Install.setupProxies(
3636
ctx,
3737
version: toolchainVersion,
3838
verbose: self.root.verbose,
3939
assumeYes: self.root.assumeYes
4040
)
41+
42+
if pathChanged {
43+
await ctx.print(Messages.refreshShell)
44+
}
4145
}
4246
}

Sources/Swiftly/Unlink.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct Unlink: SwiftlyCommand {
2727
mutating func run(_ ctx: SwiftlyCoreContext) async throws {
2828
try validateSwiftly(ctx)
2929

30+
var pathChanged = false
3031
if let proxyTo = try? Swiftly.currentPlatform.findSwiftlyBin(ctx) {
3132
let swiftlyBinDir = Swiftly.currentPlatform.swiftlyBinDir(ctx)
3233
let swiftlyBinDirContents = (try? FileManager.default.contentsOfDirectory(atPath: swiftlyBinDir.path)) ?? [String]()
@@ -43,8 +44,13 @@ struct Unlink: SwiftlyCommand {
4344

4445
if proxy.fileExists() {
4546
try FileManager.default.removeItem(at: proxy)
47+
pathChanged = true
4648
}
4749
}
4850
}
51+
52+
if pathChanged {
53+
await ctx.print(Messages.refreshShell)
54+
}
4955
}
5056
}

Sources/Swiftly/Update.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,7 @@ struct Update: SwiftlyCommand {
141141
}
142142

143143
if pathChanged {
144-
await ctx.print("""
145-
NOTE: Swiftly has updated some elements in your path and your shell may not yet be
146-
aware of the changes. You can update your shell's environment by running
147-
148-
hash -r
149-
150-
or restarting your shell.
151-
152-
""")
144+
await ctx.print(Messages.refreshShell)
153145
}
154146
}
155147

Sources/SwiftlyCore/Messages.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public struct Messages {
2+
public static let refreshShell = """
3+
NOTE: Swiftly has updated some elements in your path and your shell may not yet be
4+
aware of the changes. You can update your shell's environment by running
5+
6+
hash -r
7+
8+
or restarting your shell.
9+
10+
"""
11+
12+
public static func postInstall(_ message: String) -> String {
13+
"""
14+
There are some dependencies that should be installed before using this toolchain.
15+
You can run the following script as the system administrator (e.g. root) to prepare
16+
your system:
17+
18+
\(message)
19+
20+
"""
21+
}
22+
}

0 commit comments

Comments
 (0)