Skip to content

Refactoring output print to message #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Sources/LinuxPlatform/Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public struct Linux: Platform {
try await fs.mkdir(atPath: self.swiftlyToolchainsDir(ctx))
}

await ctx.print("Extracting toolchain...")
await ctx.message("Extracting toolchain...")
let toolchainDir = self.swiftlyToolchainsDir(ctx) / version.name

if try await fs.exists(atPath: toolchainDir) {
Expand Down Expand Up @@ -376,7 +376,7 @@ public struct Linux: Platform {
let tmpDir = self.getTempFilePath()
try await fs.mkdir(.parents, atPath: tmpDir)
try await fs.withTemporary(files: tmpDir) {
await ctx.print("Extracting new swiftly...")
await ctx.message("Extracting new swiftly...")
try extractArchive(atPath: archive) { name in
// Extract to the temporary directory
tmpDir / String(name)
Expand Down Expand Up @@ -405,15 +405,15 @@ public struct Linux: Platform {
_ ctx: SwiftlyCoreContext, toolchainFile: ToolchainFile, archive: FilePath, verbose: Bool
) async throws {
if verbose {
await ctx.print("Downloading toolchain signature...")
await ctx.message("Downloading toolchain signature...")
}

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

await ctx.print("Verifying toolchain signature...")
await ctx.message("Verifying toolchain signature...")
do {
if let mockedHomeDir = ctx.mockedHomeDir {
var env = ProcessInfo.processInfo.environment
Expand All @@ -432,7 +432,7 @@ public struct Linux: Platform {
_ ctx: SwiftlyCoreContext, archiveDownloadURL: URL, archive: FilePath, verbose: Bool
) async throws {
if verbose {
await ctx.print("Downloading swiftly signature...")
await ctx.message("Downloading swiftly signature...")
}

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

await ctx.print("Verifying swiftly signature...")
await ctx.message("Verifying swiftly signature...")
do {
if let mockedHomeDir = ctx.mockedHomeDir {
var env = ProcessInfo.processInfo.environment
Expand All @@ -461,19 +461,19 @@ public struct Linux: Platform {
-> PlatformDefinition
{
if let platformPretty {
print(
await ctx.message(
"\(platformPretty) is not an officially supported platform, but the toolchains for another platform may still work on it."
)
} else {
print(
await ctx.message(
"This platform could not be detected, but a toolchain for one of the supported platforms may work on it."
)
}

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

print(
await ctx.message(
"""
Please select the platform to use for toolchain downloads:

Expand Down Expand Up @@ -526,7 +526,7 @@ public struct Linux: Platform {
if disableConfirmation {
throw SwiftlyError(message: message)
} else {
print(message)
await ctx.message(message)
}
return await self.manualSelectPlatform(ctx, platformPretty)
}
Expand Down Expand Up @@ -557,7 +557,7 @@ public struct Linux: Platform {
if disableConfirmation {
throw SwiftlyError(message: message)
} else {
print(message)
await ctx.message(message)
}
return await self.manualSelectPlatform(ctx, platformPretty)
}
Expand All @@ -568,7 +568,7 @@ public struct Linux: Platform {
if disableConfirmation {
throw SwiftlyError(message: message)
} else {
print(message)
await ctx.message(message)
}
return await self.manualSelectPlatform(ctx, platformPretty)
}
Expand All @@ -580,7 +580,7 @@ public struct Linux: Platform {
if disableConfirmation {
throw SwiftlyError(message: message)
} else {
print(message)
await ctx.message(message)
}
return await self.manualSelectPlatform(ctx, platformPretty)
}
Expand All @@ -596,7 +596,7 @@ public struct Linux: Platform {
if disableConfirmation {
throw SwiftlyError(message: message)
} else {
print(message)
await ctx.message(message)
}
return await self.manualSelectPlatform(ctx, platformPretty)
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/MacOSPlatform/MacOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ public struct MacOS: Platform {

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

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

if !(try await fs.exists(atPath: toolchainDir)) {
try await fs.mkdir(atPath: toolchainDir)
}

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

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

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

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

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

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

Expand All @@ -149,7 +149,7 @@ public struct MacOS: Platform {
async throws
{
if verbose {
await ctx.print("Uninstalling package in user home directory... ")
await ctx.message("Uninstalling package in user home directory... ")
}

let toolchainDir = self.swiftlyToolchainsDir(ctx) / "\(toolchain.identifier).xctoolchain"
Expand Down
12 changes: 6 additions & 6 deletions Sources/Swiftly/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct Init: SwiftlyCommand {
"""
}

await ctx.print(msg)
await ctx.message(msg)

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

if overwrite || !envFileExists {
await ctx.print("Creating shell environment file for the user...")
await ctx.message("Creating shell environment file for the user...")
var env = ""
if shell.hasSuffix("fish") {
env = """
Expand Down Expand Up @@ -221,7 +221,7 @@ struct Init: SwiftlyCommand {
}

if !noModifyProfile {
await ctx.print("Updating profile...")
await ctx.message("Updating profile...")

let userHome = ctx.mockedHomeDir ?? fs.home

Expand Down Expand Up @@ -275,7 +275,7 @@ struct Init: SwiftlyCommand {
}

if !quietShellFollowup {
await ctx.print("""
await ctx.message("""
To begin using installed swiftly from your current shell, first run the following command:
\(sourceLine)

Expand All @@ -284,7 +284,7 @@ struct Init: SwiftlyCommand {

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

if let postInstall {
await ctx.print(Messages.postInstall(postInstall))
await ctx.message(Messages.postInstall(postInstall))
}
}
}
26 changes: 13 additions & 13 deletions Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct Install: SwiftlyCommand {

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

for executable in overwrite {
await ctx.print(" \(swiftlyBinDir / executable)")
await ctx.message(" \(swiftlyBinDir / executable)")
}

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

if verbose {
await ctx.print("Setting up toolchain proxies...")
await ctx.message("Setting up toolchain proxies...")
}

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

Expand All @@ -263,7 +263,7 @@ struct Install: SwiftlyCommand {
requireSignatureValidation: verifySignature
)

await ctx.print("Installing \(version)")
await ctx.message("Installing \(version)")

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

let lockFile = Swiftly.currentPlatform.swiftlyHomeDir(ctx) / "swiftly.lock"
if verbose {
await ctx.print("Attempting to acquire installation lock at \(lockFile) ...")
await ctx.message("Attempting to acquire installation lock at \(lockFile) ...")
}

let (pathChanged, newConfig) = try await withLock(lockFile) {
if verbose {
await ctx.print("Acquired installation lock")
await ctx.message("Acquired installation lock")
}

var config = try await Config.load(ctx)
Expand Down Expand Up @@ -390,12 +390,12 @@ struct Install: SwiftlyCommand {
if config.inUse == nil {
config.inUse = version
try config.save(ctx)
await ctx.print("The global default toolchain has been set to `\(version)`")
await ctx.message("The global default toolchain has been set to `\(version)`")
}
return (pathChanged, config)
}
config = newConfig
await ctx.print("\(version) installed successfully!")
await ctx.message("\(version) installed successfully!")
return (postInstallScript, pathChanged)
}
}
Expand All @@ -406,7 +406,7 @@ struct Install: SwiftlyCommand {
{
switch selector {
case .latest:
await ctx.print("Fetching the latest stable Swift release...")
await ctx.message("Fetching the latest stable Swift release...")

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

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

await ctx.print("Fetching the latest \(branch) branch snapshot...")
await ctx.message("Fetching the latest \(branch) branch snapshot...")

// If a date was not provided, perform a lookup to find the most recent snapshot
// for the given branch.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Swiftly/Link.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ struct Link: SwiftlyCommand {
)

if pathChanged {
await ctx.print("""
await ctx.message("""
Linked swiftly to Swift \(toolchainVersion.name).

\(Messages.refreshShell)
""")
} else {
await ctx.print("""
await ctx.message("""
Swiftly is already linked to Swift \(toolchainVersion.name).
""")
}
Expand Down
Loading