Skip to content

Commit 5ce2df0

Browse files
committed
Fix output indentation and rename CLI tool
1 parent 2ab9994 commit 5ce2df0

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ let package = Package(
193193
dependencies: ["Commands"]),
194194
.target(
195195
/** Interacts with package collections */
196-
name: "swift-package-collections",
196+
name: "swift-package-collection",
197197
dependencies: ["Commands"]),
198198
.target(
199199
/** Shim tool to find test names on OS X */

Sources/Commands/SwiftPackageCollectionsTool.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct JSONOptions: ParsableArguments {
3838

3939
public struct SwiftPackageCollectionsTool: ParsableCommand {
4040
public static var configuration = CommandConfiguration(
41-
commandName: "package-collections",
41+
commandName: "package-collection",
4242
_superCommandName: "swift",
4343
abstract: "Interact with package collections",
4444
discussion: "SEE ALSO: swift build, swift package, swift run, swift test",
@@ -202,7 +202,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
202202
let license = optionalRow("License", version.license?.type.description)
203203

204204
return """
205-
\(version.version)
205+
\(version.version)
206206
Package Name: \(version.packageName)
207207
Modules: \(modules)\(platforms)\(swiftVersions)\(license)
208208
"""
@@ -222,17 +222,18 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
222222
throw CollectionsError.invalidVersionString(versionString)
223223
}
224224

225-
print("Version: \(printedResult)")
225+
print("\(indent())Version: \(printedResult)")
226226
} else {
227227
let description = optionalRow("Description", result.package.summary)
228228
let versions = result.package.versions.map { "\($0.version)" }.joined(separator: ", ")
229229
let watchers = optionalRow("Watchers", result.package.watchersCount?.description)
230230
let readme = optionalRow("Readme", result.package.readmeURL?.absoluteString)
231231
let authors = optionalRow("Authors", result.package.authors?.map { $0.username }.joined(separator: ", "))
232-
let latestVersion = optionalRow("--------------------------------------------------------------\nLatest Version", printVersion(result.package.latestVersion))
232+
let latestVersion = optionalRow("\(String(repeating: "-", count: 60))\n\(indent())Latest Version", printVersion(result.package.latestVersion))
233233

234234
print("""
235-
\(description)Available Versions: \(versions)\(watchers)\(readme)\(authors)\(latestVersion)
235+
\(description)
236+
Available Versions: \(versions)\(watchers)\(readme)\(authors)\(latestVersion)
236237
""")
237238
}
238239
} catch { // assume URL is for a collection
@@ -252,24 +253,27 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
252253

253254
let description = optionalRow("Description", collection.overview)
254255
let keywords = optionalRow("Keywords", collection.keywords?.joined(separator: ", "))
255-
let createdAt = DateFormatter().string(from: collection.createdAt)
256-
let packages = collection.packages.map { "\($0.repository.url)" }.joined(separator: "\n")
256+
let createdAt = optionalRow("Created At", DateFormatter().string(from: collection.createdAt))
257+
let packages = collection.packages.map { "\($0.repository.url)" }.joined(separator: "\n\(indent(levels: 2))")
257258

258259
print("""
259260
Name: \(collection.name)
260-
Source: \(collection.source.url)\(description)\(keywords)
261-
Created At: \(createdAt)
261+
Source: \(collection.source.url)\(description)\(keywords)\(createdAt)
262262
Packages:
263-
\(packages)
263+
\(packages)
264264
""")
265265
}
266266
}
267267
}
268268
}
269269

270-
private func optionalRow(_ title: String, _ contents: String?) -> String {
271-
if let contents = contents {
272-
return "\n\(title): \(contents)\n"
270+
private func indent(levels: Int = 1) -> String {
271+
return String(repeating: " ", count: levels)
272+
}
273+
274+
private func optionalRow(_ title: String, _ contents: String?, indentationLevel: Int = 1) -> String {
275+
if let contents = contents, !contents.isEmpty {
276+
return "\n\(indent(levels: indentationLevel))\(title): \(contents)"
273277
} else {
274278
return ""
275279
}

Sources/swift-package-collections/CMakeLists.txt renamed to Sources/swift-package-collection/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_executable(swift-package-collections
9+
add_executable(swift-package-collection
1010
main.swift)
11-
target_link_libraries(swift-package-collections PRIVATE
11+
target_link_libraries(swift-package-collection PRIVATE
1212
Commands)
1313

1414
if(USE_CMAKE_INSTALL)
15-
install(TARGETS swift-package-collections
15+
install(TARGETS swift-package-collection
1616
RUNTIME DESTINATION bin)
1717
endif()

Utilities/bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def install(args):
379379

380380
def install_swiftpm(prefix, args):
381381
# Install swiftpm binaries.
382-
for binary in ["swift-build", "swift-test", "swift-run", "swift-package", "swift-package-collections"]:
382+
for binary in ["swift-build", "swift-test", "swift-run", "swift-package"]:
383383
dest = os.path.join(prefix, "bin")
384384
install_binary(args, binary, dest)
385385

0 commit comments

Comments
 (0)