Skip to content

Commit acfd9eb

Browse files
committed
Refactor DestinationCommand.ListDestinations
1 parent c4cfd49 commit acfd9eb

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

Sources/Commands/DestinationTools/ListDestinations.swift

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,50 +65,64 @@ extension DestinationCommand {
6565
rootPath: bundlePath
6666
)
6767

68-
for (artifactID, artifactMetadata) in parsedManifest.artifacts
69-
where artifactMetadata.type == .crossCompilationDestination {
70-
for variant in artifactMetadata.variants {
71-
let destinationJSONPath = try bundlePath
72-
.appending(RelativePath(validating: variant.path))
73-
.appending(component: "destination.json")
68+
try parsedManifest.printValidatedArtifactIDs(
69+
bundlePath: bundlePath,
70+
fileSystem: fileSystem,
71+
observabilityScope: observabilityScope
72+
)
73+
} catch {
74+
observabilityScope.emit(
75+
.warning(
76+
"Couldn't parse `info.json` manifest of a destination bundle at \(bundlePath): \(error)"
77+
)
78+
)
79+
}
80+
}
81+
}
82+
}
83+
}
7484

75-
guard fileSystem.exists(destinationJSONPath) else {
76-
observabilityScope.emit(
77-
.warning(
78-
"""
79-
Destination metadata file not found at \(
80-
destinationJSONPath
81-
) for a variant of artifact \(artifactID)
82-
"""
83-
)
84-
)
85+
private extension ArtifactsArchiveMetadata {
86+
func printValidatedArtifactIDs(
87+
bundlePath: AbsolutePath,
88+
fileSystem: FileSystem,
89+
observabilityScope: ObservabilityScope
90+
) throws {
91+
for (artifactID, artifactMetadata) in artifacts
92+
where artifactMetadata.type == .crossCompilationDestination {
93+
for variant in artifactMetadata.variants {
94+
let destinationJSONPath = try bundlePath
95+
.appending(RelativePath(validating: variant.path))
96+
.appending(component: "destination.json")
8597

86-
continue
87-
}
98+
guard fileSystem.exists(destinationJSONPath) else {
99+
observabilityScope.emit(
100+
.warning(
101+
"""
102+
Destination metadata file not found at \(
103+
destinationJSONPath
104+
) for a variant of artifact \(artifactID)
105+
"""
106+
)
107+
)
88108

89-
do {
90-
_ = try Destination(
91-
fromFile: destinationJSONPath, fileSystem: fileSystem
92-
)
93-
} catch {
94-
observabilityScope.emit(
95-
.warning(
96-
"Couldn't parse destination metadata at \(destinationJSONPath): \(error)"
97-
)
98-
)
99-
}
100-
}
109+
continue
110+
}
101111

102-
print(artifactID)
103-
}
112+
do {
113+
_ = try Destination(
114+
fromFile: destinationJSONPath, fileSystem: fileSystem
115+
)
104116
} catch {
105117
observabilityScope.emit(
106118
.warning(
107-
"Couldn't parse `info.json` manifest of a destination bundle at \(bundlePath): \(error)"
119+
"Couldn't parse destination metadata at \(destinationJSONPath): \(error)"
108120
)
109121
)
110122
}
111123
}
124+
125+
print(artifactID)
112126
}
113127
}
114128
}

0 commit comments

Comments
 (0)