11import Foundation
22
33/// The `extension` that provides static properties that are common directories.
4- extension Path {
4+ private enum Foo {
55 //MARK: Common Directories
66
77 /// Returns a `Path` containing `FileManager.default.currentDirectoryPath`.
8- public static var cwd : DynamicPath {
8+ static var cwd : DynamicPath {
99 return . init( string: FileManager . default. currentDirectoryPath)
1010 }
1111
1212 /// Returns a `Path` representing the root path.
13- public static var root : DynamicPath {
13+ static var root : DynamicPath {
1414 return . init( string: " / " )
1515 }
1616
@@ -27,7 +27,7 @@ extension Path {
2727#endif
2828
2929 /// Returns a `Path` representing the user’s home directory
30- public static var home : DynamicPath {
30+ static var home : DynamicPath {
3131 let string : String
3232 #if os(macOS)
3333 if #available( OSX 10 . 12 , * ) {
@@ -70,7 +70,7 @@ extension Path {
7070 - Note: There is no standard location for documents on Linux, thus we return `~/Documents`.
7171 - Note: You should create a subdirectory before creating any files.
7272 */
73- public static var documents : DynamicPath {
73+ static var documents : DynamicPath {
7474 return path ( for: . documentDirectory)
7575 }
7676
@@ -79,7 +79,7 @@ extension Path {
7979 - Note: On Linux this is `XDG_CACHE_HOME`.
8080 - Note: You should create a subdirectory before creating any files.
8181 */
82- public static var caches : DynamicPath {
82+ static var caches : DynamicPath {
8383 return path ( for: . cachesDirectory)
8484 }
8585
@@ -88,7 +88,7 @@ extension Path {
8888 - Note: On Linux is `XDG_DATA_HOME`.
8989 - Note: You should create a subdirectory before creating any files.
9090 */
91- public static var applicationSupport : DynamicPath {
91+ static var applicationSupport : DynamicPath {
9292 return path ( for: . applicationSupportDirectory)
9393 }
9494}
@@ -108,13 +108,35 @@ func defaultUrl(for searchPath: FileManager.SearchPathDirectory) -> DynamicPath
108108}
109109#endif
110110
111+ /// The `extension` that provides static properties that are common directories.
111112#if swift(>=5.5)
112- extension Pathish where Self == Path {
113- static var home : DynamicPath { Path . home }
114- static var root : DynamicPath { Path . root }
115- static var cwd : DynamicPath { Path . cwd }
116- static var documents : DynamicPath { Path . documents }
117- static var caches : DynamicPath { Path . caches }
118- static var applicationSupport : DynamicPath { Path . applicationSupport }
113+ public extension Pathish where Self == Path {
114+ static var home : DynamicPath { return Foo . home }
115+ static var root : DynamicPath { return Foo . root }
116+ static var cwd : DynamicPath { return Foo . cwd }
117+ static var documents : DynamicPath { return Foo . documents }
118+ static var caches : DynamicPath { return Foo . caches }
119+ static var applicationSupport : DynamicPath { return Foo . applicationSupport }
120+ static func source( for filePath: String = #filePath) -> ( file: DynamicPath , directory: DynamicPath ) {
121+ return Foo . source ( for: filePath)
122+ }
123+ }
124+ #else
125+ public extension Path {
126+ static var home : DynamicPath { return Foo . home }
127+ static var root : DynamicPath { return Foo . root }
128+ static var cwd : DynamicPath { return Foo . cwd }
129+ static var documents : DynamicPath { return Foo . documents }
130+ static var caches : DynamicPath { return Foo . caches }
131+ static var applicationSupport : DynamicPath { return Foo . applicationSupport }
132+ #if swift(>=5.3)
133+ static func source( for filePath: String = #filePath) -> ( file: DynamicPath , directory: DynamicPath ) {
134+ return Foo . source ( for: filePath)
135+ }
136+ #else
137+ static func source( for file: String = #file) -> ( file: DynamicPath , directory: DynamicPath ) {
138+ return Foo . source ( for: file)
139+ }
140+ #endif
119141}
120142#endif
0 commit comments