@@ -81,14 +81,17 @@ struct Install: SwiftlyCommand {
81
81
) )
82
82
var progressFile : FilePath ?
83
83
84
+ @Option ( name: . long, help: " Output format (text, json) " )
85
+ var format : SwiftlyCore . OutputFormat = . text
86
+
84
87
@OptionGroup var root : GlobalOptions
85
88
86
89
private enum CodingKeys : String , CodingKey {
87
- case version, use, verify, postInstallFile, root, progressFile
90
+ case version, use, verify, postInstallFile, root, progressFile, format
88
91
}
89
92
90
93
mutating func run( ) async throws {
91
- try await self . run ( Swiftly . createDefaultContext ( ) )
94
+ try await self . run ( Swiftly . createDefaultContext ( format : self . format ) )
92
95
}
93
96
94
97
private func swiftlyHomeDir( _ ctx: SwiftlyCoreContext ) -> FilePath {
@@ -266,7 +269,10 @@ struct Install: SwiftlyCommand {
266
269
progressFile: FilePath? = nil
267
270
) async throws -> ( postInstall: String? , pathChanged: Bool) {
268
271
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)
270
276
return ( nil , false )
271
277
}
272
278
@@ -316,6 +322,8 @@ struct Install: SwiftlyCommand {
316
322
if let progressFile
317
323
{
318
324
try JsonFileProgressReporter ( ctx, filePath: progressFile)
325
+ } else if ctx. format == . json {
326
+ nil
319
327
} else {
320
328
ConsoleProgressReporter ( stream: stdoutStream, header: " Downloading \( version) " )
321
329
}
@@ -351,7 +359,7 @@ struct Install: SwiftlyCommand {
351
359
lastUpdate = Date ( )
352
360
353
361
do {
354
- try await animation. update (
362
+ try await animation? . update (
355
363
step: progress. receivedBytes,
356
364
total: progress. totalBytes!,
357
365
text:
@@ -368,10 +376,10 @@ struct Install: SwiftlyCommand {
368
376
throw SwiftlyError (
369
377
message: " \( version) does not exist at URL \( notFound. url) , exiting " )
370
378
} catch {
371
- try ? await animation. complete ( success: false )
379
+ try ? await animation? . complete ( success: false )
372
380
throw error
373
381
}
374
- try await animation. complete ( success: true )
382
+ try await animation? . complete ( success: true )
375
383
376
384
if verifySignature {
377
385
try await Swiftly . currentPlatform. verifyToolchainSignature (
@@ -427,7 +435,11 @@ struct Install: SwiftlyCommand {
427
435
return ( pathChanged, config)
428
436
}
429
437
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)
431
443
return ( postInstallScript, pathChanged)
432
444
}
433
445
}
0 commit comments