Skip to content

Commit ab6757f

Browse files
authored
Refactoring output print to message (#377)
1 parent 1afee41 commit ab6757f

File tree

15 files changed

+101
-98
lines changed

15 files changed

+101
-98
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public struct Linux: Platform {
342342
try await fs.mkdir(atPath: self.swiftlyToolchainsDir(ctx))
343343
}
344344

345-
await ctx.print("Extracting toolchain...")
345+
await ctx.message("Extracting toolchain...")
346346
let toolchainDir = self.swiftlyToolchainsDir(ctx) / version.name
347347

348348
if try await fs.exists(atPath: toolchainDir) {
@@ -376,7 +376,7 @@ public struct Linux: Platform {
376376
let tmpDir = self.getTempFilePath()
377377
try await fs.mkdir(.parents, atPath: tmpDir)
378378
try await fs.withTemporary(files: tmpDir) {
379-
await ctx.print("Extracting new swiftly...")
379+
await ctx.message("Extracting new swiftly...")
380380
try extractArchive(atPath: archive) { name in
381381
// Extract to the temporary directory
382382
tmpDir / String(name)
@@ -405,15 +405,15 @@ public struct Linux: Platform {
405405
_ ctx: SwiftlyCoreContext, toolchainFile: ToolchainFile, archive: FilePath, verbose: Bool
406406
) async throws {
407407
if verbose {
408-
await ctx.print("Downloading toolchain signature...")
408+
await ctx.message("Downloading toolchain signature...")
409409
}
410410

411411
let sigFile = self.getTempFilePath()
412412
try await fs.create(file: sigFile, contents: nil)
413413
try await fs.withTemporary(files: sigFile) {
414414
try await ctx.httpClient.getSwiftToolchainFileSignature(toolchainFile).download(to: sigFile)
415415

416-
await ctx.print("Verifying toolchain signature...")
416+
await ctx.message("Verifying toolchain signature...")
417417
do {
418418
if let mockedHomeDir = ctx.mockedHomeDir {
419419
var env = ProcessInfo.processInfo.environment
@@ -432,7 +432,7 @@ public struct Linux: Platform {
432432
_ ctx: SwiftlyCoreContext, archiveDownloadURL: URL, archive: FilePath, verbose: Bool
433433
) async throws {
434434
if verbose {
435-
await ctx.print("Downloading swiftly signature...")
435+
await ctx.message("Downloading swiftly signature...")
436436
}
437437

438438
let sigFile = self.getTempFilePath()
@@ -442,7 +442,7 @@ public struct Linux: Platform {
442442
url: archiveDownloadURL.appendingPathExtension("sig")
443443
).download(to: sigFile)
444444

445-
await ctx.print("Verifying swiftly signature...")
445+
await ctx.message("Verifying swiftly signature...")
446446
do {
447447
if let mockedHomeDir = ctx.mockedHomeDir {
448448
var env = ProcessInfo.processInfo.environment
@@ -461,19 +461,19 @@ public struct Linux: Platform {
461461
-> PlatformDefinition
462462
{
463463
if let platformPretty {
464-
print(
464+
await ctx.message(
465465
"\(platformPretty) is not an officially supported platform, but the toolchains for another platform may still work on it."
466466
)
467467
} else {
468-
print(
468+
await ctx.message(
469469
"This platform could not be detected, but a toolchain for one of the supported platforms may work on it."
470470
)
471471
}
472472

473473
let selections = self.linuxPlatforms.enumerated().map { "\($0 + 1)) \($1.namePretty)" }.joined(
474474
separator: "\n")
475475

476-
print(
476+
await ctx.message(
477477
"""
478478
Please select the platform to use for toolchain downloads:
479479
@@ -526,7 +526,7 @@ public struct Linux: Platform {
526526
if disableConfirmation {
527527
throw SwiftlyError(message: message)
528528
} else {
529-
print(message)
529+
await ctx.message(message)
530530
}
531531
return await self.manualSelectPlatform(ctx, platformPretty)
532532
}
@@ -557,7 +557,7 @@ public struct Linux: Platform {
557557
if disableConfirmation {
558558
throw SwiftlyError(message: message)
559559
} else {
560-
print(message)
560+
await ctx.message(message)
561561
}
562562
return await self.manualSelectPlatform(ctx, platformPretty)
563563
}
@@ -568,7 +568,7 @@ public struct Linux: Platform {
568568
if disableConfirmation {
569569
throw SwiftlyError(message: message)
570570
} else {
571-
print(message)
571+
await ctx.message(message)
572572
}
573573
return await self.manualSelectPlatform(ctx, platformPretty)
574574
}
@@ -580,7 +580,7 @@ public struct Linux: Platform {
580580
if disableConfirmation {
581581
throw SwiftlyError(message: message)
582582
} else {
583-
print(message)
583+
await ctx.message(message)
584584
}
585585
return await self.manualSelectPlatform(ctx, platformPretty)
586586
}
@@ -596,7 +596,7 @@ public struct Linux: Platform {
596596
if disableConfirmation {
597597
throw SwiftlyError(message: message)
598598
} else {
599-
print(message)
599+
await ctx.message(message)
600600
}
601601
return await self.manualSelectPlatform(ctx, platformPretty)
602602
}

Sources/MacOSPlatform/MacOS.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ public struct MacOS: Platform {
6969

7070
if toolchainsDir == self.defaultToolchainsDirectory {
7171
// If the toolchains go into the default user location then we use the installer to install them
72-
await ctx.print("Installing package in user home directory...")
72+
await ctx.message("Installing package in user home directory...")
7373

7474
try await sys.installer(.verbose, .pkg(tmpFile), .target("CurrentUserHomeDirectory")).run(self, quiet: !verbose)
7575
} else {
7676
// Otherwise, we extract the pkg into the requested toolchains directory.
77-
await ctx.print("Expanding pkg...")
77+
await ctx.message("Expanding pkg...")
7878
let tmpDir = fs.mktemp()
7979
let toolchainDir = toolchainsDir / "\(version.identifier).xctoolchain"
8080

8181
if !(try await fs.exists(atPath: toolchainDir)) {
8282
try await fs.mkdir(atPath: toolchainDir)
8383
}
8484

85-
await ctx.print("Checking package signature...")
85+
await ctx.message("Checking package signature...")
8686
do {
8787
try await sys.pkgutil().checksignature(pkg_path: tmpFile).run(self, quiet: !verbose)
8888
} catch {
@@ -92,7 +92,7 @@ public struct MacOS: Platform {
9292
}
9393

9494
// We permit the signature verification to fail during testing
95-
await ctx.print("Signature verification failed, which is allowable during testing with mocked toolchains")
95+
await ctx.message("Signature verification failed, which is allowable during testing with mocked toolchains")
9696
}
9797
try await sys.pkgutil(.verbose).expand(pkg_path: tmpFile, dir_path: tmpDir).run(self, quiet: !verbose)
9898

@@ -103,7 +103,7 @@ public struct MacOS: Platform {
103103
payload = tmpDir / "\(version.identifier)-osx-package.pkg/Payload"
104104
}
105105

106-
await ctx.print("Untarring pkg Payload...")
106+
await ctx.message("Untarring pkg Payload...")
107107
try await sys.tar(.directory(toolchainDir)).extract(.verbose, .archive(payload)).run(self, quiet: !verbose)
108108
}
109109
}
@@ -116,7 +116,7 @@ public struct MacOS: Platform {
116116
let userHomeDir = ctx.mockedHomeDir ?? fs.home
117117

118118
if ctx.mockedHomeDir == nil {
119-
await ctx.print("Extracting the swiftly package...")
119+
await ctx.message("Extracting the swiftly package...")
120120
try await sys.installer(
121121
.pkg(archive),
122122
.target("CurrentUserHomeDirectory")
@@ -138,7 +138,7 @@ public struct MacOS: Platform {
138138
throw SwiftlyError(message: "Payload file could not be found at \(tmpDir).")
139139
}
140140

141-
await ctx.print("Extracting the swiftly package into \(installDir)...")
141+
await ctx.message("Extracting the swiftly package into \(installDir)...")
142142
try await sys.tar(.directory(installDir)).extract(.verbose, .archive(payload)).run(self, quiet: false)
143143
}
144144

@@ -149,7 +149,7 @@ public struct MacOS: Platform {
149149
async throws
150150
{
151151
if verbose {
152-
await ctx.print("Uninstalling package in user home directory... ")
152+
await ctx.message("Uninstalling package in user home directory... ")
153153
}
154154

155155
let toolchainDir = self.swiftlyToolchainsDir(ctx) / "\(toolchain.identifier).xctoolchain"

Sources/Swiftly/Init.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct Init: SwiftlyCommand {
124124
"""
125125
}
126126

127-
await ctx.print(msg)
127+
await ctx.message(msg)
128128

129129
guard await ctx.promptForConfirmation(defaultBehavior: true) else {
130130
throw SwiftlyError(message: "swiftly installation has been cancelled")
@@ -193,7 +193,7 @@ struct Init: SwiftlyCommand {
193193
let envFileExists = try await fs.exists(atPath: envFile)
194194

195195
if overwrite || !envFileExists {
196-
await ctx.print("Creating shell environment file for the user...")
196+
await ctx.message("Creating shell environment file for the user...")
197197
var env = ""
198198
if shell.hasSuffix("fish") {
199199
env = """
@@ -221,7 +221,7 @@ struct Init: SwiftlyCommand {
221221
}
222222

223223
if !noModifyProfile {
224-
await ctx.print("Updating profile...")
224+
await ctx.message("Updating profile...")
225225

226226
let userHome = ctx.mockedHomeDir ?? fs.home
227227

@@ -275,7 +275,7 @@ struct Init: SwiftlyCommand {
275275
}
276276

277277
if !quietShellFollowup {
278-
await ctx.print("""
278+
await ctx.message("""
279279
To begin using installed swiftly from your current shell, first run the following command:
280280
\(sourceLine)
281281
@@ -284,7 +284,7 @@ struct Init: SwiftlyCommand {
284284

285285
// Fish doesn't have path caching, so this might only be needed for bash/zsh
286286
if pathChanged && !quietShellFollowup && !shell.hasSuffix("fish") {
287-
await ctx.print("""
287+
await ctx.message("""
288288
Your shell caches items on your path for better performance. Swiftly has added
289289
items to your path that may not get picked up right away. You can update your
290290
shell's environment by running
@@ -297,7 +297,7 @@ struct Init: SwiftlyCommand {
297297
}
298298

299299
if let postInstall {
300-
await ctx.print(Messages.postInstall(postInstall))
300+
await ctx.message(Messages.postInstall(postInstall))
301301
}
302302
}
303303
}

Sources/Swiftly/Install.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct Install: SwiftlyCommand {
115115

116116
// Fish doesn't cache its path, so this instruction is not necessary.
117117
if pathChanged && !shell.hasSuffix("fish") {
118-
await ctx.print(
118+
await ctx.message(
119119
"""
120120
NOTE: Swiftly has updated some elements in your path and your shell may not yet be
121121
aware of the changes. You can update your shell's environment by running
@@ -177,10 +177,10 @@ struct Install: SwiftlyCommand {
177177
let overwrite = Set(toolchainBinDirContents).subtracting(existingProxies).intersection(
178178
swiftlyBinDirContents)
179179
if !overwrite.isEmpty && !assumeYes {
180-
await ctx.print("The following existing executables will be overwritten:")
180+
await ctx.message("The following existing executables will be overwritten:")
181181

182182
for executable in overwrite {
183-
await ctx.print(" \(swiftlyBinDir / executable)")
183+
await ctx.message(" \(swiftlyBinDir / executable)")
184184
}
185185

186186
guard await ctx.promptForConfirmation(defaultBehavior: false) else {
@@ -189,7 +189,7 @@ struct Install: SwiftlyCommand {
189189
}
190190

191191
if verbose {
192-
await ctx.print("Setting up toolchain proxies...")
192+
await ctx.message("Setting up toolchain proxies...")
193193
}
194194

195195
let proxiesToCreate = Set(toolchainBinDirContents).subtracting(swiftlyBinDirContents).union(
@@ -251,7 +251,7 @@ struct Install: SwiftlyCommand {
251251
assumeYes: Bool
252252
) async throws -> (postInstall: String?, pathChanged: Bool) {
253253
guard !config.installedToolchains.contains(version) else {
254-
await ctx.print("\(version) is already installed.")
254+
await ctx.message("\(version) is already installed.")
255255
return (nil, false)
256256
}
257257

@@ -263,7 +263,7 @@ struct Install: SwiftlyCommand {
263263
requireSignatureValidation: verifySignature
264264
)
265265

266-
await ctx.print("Installing \(version)")
266+
await ctx.message("Installing \(version)")
267267

268268
let tmpFile = fs.mktemp(ext: ".\(Swiftly.currentPlatform.toolchainFileExtension)")
269269
try await fs.create(file: tmpFile, contents: nil)
@@ -352,12 +352,12 @@ struct Install: SwiftlyCommand {
352352

353353
let lockFile = Swiftly.currentPlatform.swiftlyHomeDir(ctx) / "swiftly.lock"
354354
if verbose {
355-
await ctx.print("Attempting to acquire installation lock at \(lockFile) ...")
355+
await ctx.message("Attempting to acquire installation lock at \(lockFile) ...")
356356
}
357357

358358
let (pathChanged, newConfig) = try await withLock(lockFile) {
359359
if verbose {
360-
await ctx.print("Acquired installation lock")
360+
await ctx.message("Acquired installation lock")
361361
}
362362

363363
var config = try await Config.load(ctx)
@@ -390,12 +390,12 @@ struct Install: SwiftlyCommand {
390390
if config.inUse == nil {
391391
config.inUse = version
392392
try config.save(ctx)
393-
await ctx.print("The global default toolchain has been set to `\(version)`")
393+
await ctx.message("The global default toolchain has been set to `\(version)`")
394394
}
395395
return (pathChanged, config)
396396
}
397397
config = newConfig
398-
await ctx.print("\(version) installed successfully!")
398+
await ctx.message("\(version) installed successfully!")
399399
return (postInstallScript, pathChanged)
400400
}
401401
}
@@ -406,7 +406,7 @@ struct Install: SwiftlyCommand {
406406
{
407407
switch selector {
408408
case .latest:
409-
await ctx.print("Fetching the latest stable Swift release...")
409+
await ctx.message("Fetching the latest stable Swift release...")
410410

411411
guard
412412
let release = try await ctx.httpClient.getReleaseToolchains(
@@ -429,7 +429,7 @@ struct Install: SwiftlyCommand {
429429
return .stable(ToolchainVersion.StableRelease(major: major, minor: minor, patch: patch))
430430
}
431431

432-
await ctx.print("Fetching the latest stable Swift \(major).\(minor) release...")
432+
await ctx.message("Fetching the latest stable Swift \(major).\(minor) release...")
433433
// If a patch was not provided, perform a lookup to get the latest patch release
434434
// of the provided major/minor version pair.
435435
let toolchain = try await ctx.httpClient.getReleaseToolchains(
@@ -449,7 +449,7 @@ struct Install: SwiftlyCommand {
449449
return ToolchainVersion(snapshotBranch: branch, date: date)
450450
}
451451

452-
await ctx.print("Fetching the latest \(branch) branch snapshot...")
452+
await ctx.message("Fetching the latest \(branch) branch snapshot...")
453453

454454
// If a date was not provided, perform a lookup to find the most recent snapshot
455455
// for the given branch.

Sources/Swiftly/Link.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ struct Link: SwiftlyCommand {
4343
)
4444

4545
if pathChanged {
46-
await ctx.print("""
46+
await ctx.message("""
4747
Linked swiftly to Swift \(toolchainVersion.name).
4848
4949
\(Messages.refreshShell)
5050
""")
5151
} else {
52-
await ctx.print("""
52+
await ctx.message("""
5353
Swiftly is already linked to Swift \(toolchainVersion.name).
5454
""")
5555
}

0 commit comments

Comments
 (0)