Skip to content

Commit 269b459

Browse files
committed
Print message to reload shell
1 parent 5699c19 commit 269b459

File tree

6 files changed

+41
-48
lines changed

6 files changed

+41
-48
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-
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+
ctx.print(Messages.refreshShell)
285276
}
286277

287278
if let postInstall {
288-
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+
ctx.print(Messages.postInstall(postInstall))
296280
}
297281
}
298282
}

Sources/Swiftly/Install.swift

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,41 +96,26 @@ struct Install: SwiftlyCommand {
9696

9797
// Fish doesn't cache its path, so this instruction is not necessary.
9898
if pathChanged && !shell.hasSuffix("fish") {
99-
ctx.print("""
100-
NOTE: Swiftly has updated some elements in your path and your shell may not yet be
101-
aware of the changes. You can update your shell's environment by running
102-
103-
hash -r
104-
105-
or restarting your shell.
106-
107-
""")
99+
ctx.print(Messages.refreshShell)
108100
}
109101

110102
if let postInstallScript {
111103
guard let postInstallFile = self.postInstallFile else {
112-
throw SwiftlyError(message: """
113-
114-
There are some dependencies that should be installed before using this toolchain.
115-
You can run the following script as the system administrator (e.g. root) to prepare
116-
your system:
117-
118-
\(postInstallScript)
119-
""")
104+
throw SwiftlyError(message: Messages.postInstall(postInstallScript))
120105
}
121106

122107
try Data(postInstallScript.utf8).write(to: URL(fileURLWithPath: postInstallFile), options: .atomic)
123108
}
124-
}
125-
109+
}
110+
126111
public static func setupProxies(
127112
_ ctx: SwiftlyCoreContext,
128113
version: ToolchainVersion,
129114
verbose: Bool,
130115
assumeYes: Bool
131116
) throws -> Bool {
132117
var pathChanged = false
133-
118+
134119
// Create proxies if we have a location where we can point them
135120
if let proxyTo = try? Swiftly.currentPlatform.findSwiftlyBin(ctx) {
136121
// Ensure swiftly doesn't overwrite any existing executables without getting confirmation first.

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 Install.setupProxies(
35+
let pathChanged = try Install.setupProxies(
3636
ctx,
3737
version: toolchainVersion,
3838
verbose: self.root.verbose,
3939
assumeYes: self.root.assumeYes
4040
)
41+
42+
if pathChanged {
43+
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+
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-
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+
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)