1
1
import ArgumentParser
2
2
import Foundation
3
- import Files
4
3
import Yams
5
4
6
5
enum OutputFormat : String , ExpressibleByArgument {
@@ -19,10 +18,6 @@ extension TodoList {
19
18
}
20
19
}
21
20
22
- enum DownstreamError : Error {
23
- case fileNotFound( path: String )
24
- }
25
-
26
21
struct DownstreamArgument : ParsableCommand {
27
22
@Option ( name: . shortAndLong, help: " The format of the output " )
28
23
var outputFormat : OutputFormat = . humanFriendly
@@ -51,16 +46,18 @@ struct DownstreamArgument: ParsableCommand {
51
46
return associationsFile. associations. matches ( path)
52
47
} else {
53
48
// This path should be coming from git diff, so we expect it to be valid
54
- let changedFile = try ! File ( path: path)
49
+ let changedFile = URL ( fileURLWithPath: path)
50
+ let parent = changedFile. deletingLastPathComponent ( )
51
+ let downstreamYML = changedFile. appendingPathComponent ( " downstream.yml " )
55
52
56
53
if
57
- let parent = changedFile . parent ,
58
- let downsteamYML = try ? parent . file ( named : " downstream.yml " ) . read ( )
54
+ let contentData = FileManager . default . contents ( atPath : downstreamYML . path ) ,
55
+ let associations = String ( data : contentData , encoding : . utf8 )
59
56
{
60
- guard let associationsFile = try ? decoder. decode ( AssociationsFile . self, from: downsteamYML ) else {
57
+ guard let associationsFile = try ? decoder. decode ( AssociationsFile . self, from: associations ) else {
61
58
throw ValidationError ( " \( parent. path) downstream.yml could not be parsed " )
62
59
}
63
- let fileName = changedFile. name
60
+ let fileName = changedFile. lastPathComponent
64
61
return associationsFile. associations. matches ( fileName)
65
62
}
66
63
}
0 commit comments