-
Notifications
You must be signed in to change notification settings - Fork 3
/
ListCommand.swift
41 lines (36 loc) · 1.54 KB
/
ListCommand.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import ArgumentParser
import Foundation
struct ListCommand: ParsableCommand {
static var configuration = CommandConfiguration(commandName: "list", abstract: "Lists all dependencies and possible updates")
@Argument(help: "Path of the swift package") var folder: String = "."
@ArgumentParser.Flag(help: "Do not include indirect dependencies.") private var excludeIndirect = false
@ArgumentParser.Flag(name: .shortAndLong, help: "Do not include dependencies without update.") private var updatesOnly = false
func run() throws {
let folder = URL(fileURLWithPath: folder)
guard folder.hasDirectoryPath else {
print("Folder argument must be a directory.")
throw ExitCode.failure
}
do {
var dependencies = try Dependency.loadDependencies(from: folder)
if excludeIndirect {
dependencies = dependencies.filter { $0.requirement != nil }
}
if updatesOnly {
dependencies = dependencies.filter { $0.update != nil && $0.update != .skipped }
}
if dependencies.isEmpty {
if updatesOnly {
print("Everything up-to-date!".green)
} else {
print("No dependencies found.".green)
}
} else {
print(dependencies.map { String(describing: $0) }.joined(separator: "\n\n"))
}
} catch {
print(error.localizedDescription)
throw ExitCode.failure
}
}
}