Packages/FoldKit/Sources/foldlint/main.swift
33 lines · 904 bytes
1 symbol in this file
1import FoldFormat
2import Folding
3import Foundation
4
5// foldlint <model.fold>...
6//
7// Prints each defect as `<path>: <defect>`, one per line, and exits 1 when there is one. A file
8// that validates has its steps read and its layer motion checked.
9
10let paths = Array(CommandLine.arguments.dropFirst())
11guard !paths.isEmpty else {
12 FileHandle.standardError.write(Data("usage: foldlint <model.fold>...\n".utf8))
13 exit(2)
14}
15
16var clean = true
17for path in paths {
18 func report(_ defect: Any) {
19 print("\(path): \(defect)")
20 clean = false
21 }
22 do {
23 let file = try FoldFile(contentsOf: URL(fileURLWithPath: path))
24 let defects = validate(file)
25 defects.forEach(report)
26 guard defects.isEmpty else { continue }
27 _ = try readSteps(file)
28 layerMotionDefects(file).forEach(report)
29 } catch {
30 report(error)
31 }
32}
33exit(clean ? 0 : 1)