@@ -18,29 +18,18 @@ import ArgumentParser
18
18
struct CLIHelper {
19
19
static func resolvePath( from input: String ) throws -> String {
20
20
let fileManager = FileManager . default
21
- var filePath : URL !
22
21
23
- // Small helper function used to determine if path is not a folder.
24
- func pathIsNotDirectory( _ path: String ) -> Bool {
25
- var isDirectory = ObjCBool ( false )
26
- if fileManager. fileExists ( atPath: path, isDirectory: & isDirectory) {
27
- return !isDirectory. boolValue
28
- } else {
29
- return true
30
- }
31
- }
32
-
33
22
let pathString = canonicalPath ( input)
34
23
35
24
guard pathIsNotDirectory ( pathString) else {
36
- throw ValidationError ( " The path entered is to a directory" )
25
+ throw ValidationError ( " \( pathString ) is a directory" )
37
26
}
38
27
39
28
if !fileManager. fileExists ( atPath: pathString) {
40
29
let createSuccess = fileManager. createFile ( atPath: pathString, contents: nil , attributes: nil )
41
30
42
31
guard createSuccess else {
43
- throw RuntimeError ( " Could not create a file " )
32
+ throw RuntimeError ( " Could not create \( pathString ) " )
44
33
}
45
34
}
46
35
@@ -77,9 +66,20 @@ struct CLIHelper {
77
66
}
78
67
}
79
68
}
80
-
69
+
70
+
71
+ // MARK: - Helper Functions
81
72
static func canonicalPath( _ path: String ) -> String {
82
73
return URL ( fileURLWithPath: path) . standardizedFileURL. resolvingSymlinksInPath ( ) . path
83
74
}
75
+
76
+ static func pathIsNotDirectory( _ path: String ) -> Bool {
77
+ var isDirectory = ObjCBool ( false )
78
+ if FileManager . default. fileExists ( atPath: path, isDirectory: & isDirectory) {
79
+ return !isDirectory. boolValue
80
+ } else {
81
+ return true
82
+ }
83
+ }
84
84
}
85
85
0 commit comments