@@ -1,16 +1,16 @@
import Foundation
import Foundation
// / T h e ` e x t e n s i o n ` t h a t p r o v i d e s s t a t i c p r o p e r t i e s t h a t a r e c o m m o n d i r e c t o r i e s .
// / T h e ` e x t e n s i o n ` t h a t p r o v i d e s s t a t i c p r o p e r t i e s t h a t a r e c o m m o n d i r e c t o r i e s .
extension Path {
private enum Foo {
// MARK: C o m m o n D i r e c t o r i e s
// MARK: C o m m o n D i r e c t o r i e s
// / R e t u r n s a ` P a t h ` c o n t a i n i n g ` F i l e M a n a g e r . d e f a u l t . c u r r e n t D i r e c t o r y P a t h ` .
// / R e t u r n s a ` P a t h ` c o n t a i n i n g ` F i l e M a n a g e r . d e f a u l t . c u r r e n t D i r e c t o r y P a t h ` .
public static var cwd : DynamicPath {
static var cwd : DynamicPath {
return . init ( string : FileManager . default . currentDirectoryPath )
return . init ( string : FileManager . default . currentDirectoryPath )
}
}
// / R e t u r n s a ` P a t h ` r e p r e s e n t i n g t h e r o o t p a t h .
// / R e t u r n s a ` P a t h ` r e p r e s e n t i n g t h e r o o t p a t h .
public static var root : DynamicPath {
static var root : DynamicPath {
return . init ( string : " / " )
return . init ( string : " / " )
}
}
@@ -27,7 +27,7 @@ extension Path {
#endif
#endif
// / R e t u r n s a ` P a t h ` r e p r e s e n t i n g t h e u s e r ’ s h o m e d i r e c t o r y
// / R e t u r n s a ` P a t h ` r e p r e s e n t i n g t h e u s e r ’ s h o m e d i r e c t o r y
public static var home : DynamicPath {
static var home : DynamicPath {
let string : String
let string : String
#if os ( macOS )
#if os ( macOS )
if #available ( OSX 10.12 , * ) {
if #available ( OSX 10.12 , * ) {
@@ -70,7 +70,7 @@ extension Path {
- N o t e : T h e r e i s n o s t a n d a r d l o c a t i o n f o r d o c u m e n t s o n L i n u x , t h u s w e r e t u r n ` ~ / D o c u m e n t s ` .
- N o t e : T h e r e i s n o s t a n d a r d l o c a t i o n f o r d o c u m e n t s o n L i n u x , t h u s w e r e t u r n ` ~ / D o c u m e n t s ` .
- N o t e : Y o u s h o u l d c r e a t e a s u b d i r e c t o r y b e f o r e c r e a t i n g a n y f i l e s .
- N o t e : Y o u s h o u l d c r e a t e a s u b d i r e c t o r y b e f o r e c r e a t i n g a n y f i l e s .
*/
*/
public static var documents : DynamicPath {
static var documents : DynamicPath {
return path ( for : . documentDirectory )
return path ( for : . documentDirectory )
}
}
@@ -79,7 +79,7 @@ extension Path {
- N o t e : O n L i n u x t h i s i s ` X D G _ C A C H E _ H O M E ` .
- N o t e : O n L i n u x t h i s i s ` X D G _ C A C H E _ H O M E ` .
- N o t e : Y o u s h o u l d c r e a t e a s u b d i r e c t o r y b e f o r e c r e a t i n g a n y f i l e s .
- N o t e : Y o u s h o u l d c r e a t e a s u b d i r e c t o r y b e f o r e c r e a t i n g a n y f i l e s .
*/
*/
public static var caches : DynamicPath {
static var caches : DynamicPath {
return path ( for : . cachesDirectory )
return path ( for : . cachesDirectory )
}
}
@@ -88,7 +88,7 @@ extension Path {
- N o t e : O n L i n u x i s ` X D G _ D A T A _ H O M E ` .
- N o t e : O n L i n u x i s ` X D G _ D A T A _ H O M E ` .
- N o t e : Y o u s h o u l d c r e a t e a s u b d i r e c t o r y b e f o r e c r e a t i n g a n y f i l e s .
- N o t e : Y o u s h o u l d c r e a t e a s u b d i r e c t o r y b e f o r e c r e a t i n g a n y f i l e s .
*/
*/
public static var applicationSupport : DynamicPath {
static var applicationSupport : DynamicPath {
return path ( for : . applicationSupportDirectory )
return path ( for : . applicationSupportDirectory )
}
}
}
}
@@ -108,13 +108,35 @@ func defaultUrl(for searchPath: FileManager.SearchPathDirectory) -> DynamicPath
}
}
#endif
#endif
// / T h e ` e x t e n s i o n ` t h a t p r o v i d e s s t a t i c p r o p e r t i e s t h a t a r e c o m m o n d i r e c t o r i e s .
#if swift ( >= 5.5 )
#if swift ( >= 5.5 )
extension Pathish where Self = = Path {
public extension Pathish where Self = = Path {
static var home : DynamicPath { Path . home }
static var home : DynamicPath { return Foo . home }
static var root : DynamicPath { Path . root }
static var root : DynamicPath { return Foo . root }
static var cwd : DynamicPath { Path . cwd }
static var cwd : DynamicPath { return Foo . cwd }
static var documents : DynamicPath { Path . documents }
static var documents : DynamicPath { return Foo . documents }
static var caches : DynamicPath { Path . caches }
static var caches : DynamicPath { return Foo . caches }
static var applicationSupport : DynamicPath { Path . applicationSupport }
static var applicationSupport : DynamicPath { return Foo . applicationSupport }
static func source ( for filePath : String = # filePath ) -> ( file : DynamicPath , directory : DynamicPath ) {
return Foo . source ( for : filePath )
}
}
#else
public extension Path {
static var home : DynamicPath { return Foo . home }
static var root : DynamicPath { return Foo . root }
static var cwd : DynamicPath { return Foo . cwd }
static var documents : DynamicPath { return Foo . documents }
static var caches : DynamicPath { return Foo . caches }
static var applicationSupport : DynamicPath { return Foo . applicationSupport }
#if swift ( >= 5.3 )
static func source ( for filePath : String = # filePath ) -> ( file : DynamicPath , directory : DynamicPath ) {
return Foo . source ( for : filePath )
}
#else
static func source ( for file : String = #file ) -> ( file : DynamicPath , directory : DynamicPath ) {
return Foo . source ( for : file )
}
#endif
}
}
#endif
#endif