@@ -81,14 +81,17 @@ struct Install: SwiftlyCommand {
8181 ) )
8282 var progressFile : FilePath ?
8383
84+ @Option ( name: . long, help: " Output format (text, json) " )
85+ var format : SwiftlyCore . OutputFormat = . text
86+
8487 @OptionGroup var root : GlobalOptions
8588
8689 private enum CodingKeys : String , CodingKey {
87- case version, use, verify, postInstallFile, root, progressFile
90+ case version, use, verify, postInstallFile, root, progressFile, format
8891 }
8992
9093 mutating func run( ) async throws {
91- try await self . run ( Swiftly . createDefaultContext ( ) )
94+ try await self . run ( Swiftly . createDefaultContext ( format : self . format ) )
9295 }
9396
9497 private func swiftlyHomeDir( _ ctx: SwiftlyCoreContext ) -> FilePath {
@@ -266,7 +269,10 @@ struct Install: SwiftlyCommand {
266269 progressFile: FilePath? = nil
267270 ) async throws -> ( postInstall: String? , pathChanged: Bool) {
268271 guard !config. installedToolchains. contains ( version) else {
269- await ctx. message ( " \( version) is already installed. " )
272+ let installInfo = InstallInfo (
273+ version: version, alreadyInstalled: true
274+ )
275+ try await ctx. output ( installInfo)
270276 return ( nil , false )
271277 }
272278
@@ -312,16 +318,18 @@ struct Install: SwiftlyCommand {
312318 }
313319 }
314320
315- let animation : ProgressReporterProtocol =
321+ let animation : ProgressReporterProtocol ? =
316322 if let progressFile
317323 {
318324 try JsonFileProgressReporter ( ctx, filePath: progressFile)
325+ } else if ctx. format == . json {
326+ nil
319327 } else {
320328 ConsoleProgressReporter ( stream: stdoutStream, header: " Downloading \( version) " )
321329 }
322330
323331 defer {
324- try ? animation. close ( )
332+ try ? animation? . close ( )
325333 }
326334
327335 var lastUpdate = Date ( )
@@ -351,7 +359,7 @@ struct Install: SwiftlyCommand {
351359 lastUpdate = Date ( )
352360
353361 do {
354- try await animation. update (
362+ try await animation? . update (
355363 step: progress. receivedBytes,
356364 total: progress. totalBytes!,
357365 text:
@@ -368,10 +376,10 @@ struct Install: SwiftlyCommand {
368376 throw SwiftlyError (
369377 message: " \( version) does not exist at URL \( notFound. url) , exiting " )
370378 } catch {
371- try ? await animation. complete ( success: false )
379+ try ? await animation? . complete ( success: false )
372380 throw error
373381 }
374- try await animation. complete ( success: true )
382+ try await animation? . complete ( success: true )
375383
376384 if verifySignature {
377385 try await Swiftly . currentPlatform. verifyToolchainSignature (
@@ -427,7 +435,11 @@ struct Install: SwiftlyCommand {
427435 return ( pathChanged, config)
428436 }
429437 config = newConfig
430- await ctx. message ( " \( version) installed successfully! " )
438+ let installInfo = InstallInfo (
439+ version: version,
440+ alreadyInstalled: false
441+ )
442+ try await ctx. output ( installInfo)
431443 return ( postInstallScript, pathChanged)
432444 }
433445 }
0 commit comments