Minor documentation fixes
[ci skip]
This commit is contained in:
@@ -28,7 +28,7 @@ print(bar) // => /bar
|
|||||||
print(bar.isFile) // => true
|
print(bar.isFile) // => true
|
||||||
|
|
||||||
// careful API considerations so as to avoid common bugs
|
// careful API considerations so as to avoid common bugs
|
||||||
let foo = try Path.root.join("foo").copy(into: Path.root.mkdir("bar"))
|
let foo = try Path.root.join("foo").copy(into: Path.root.join("bar").mkdir())
|
||||||
print(foo) // => /bar/foo
|
print(foo) // => /bar/foo
|
||||||
print(foo.isFile) // => true
|
print(foo.isFile) // => true
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import Foundation
|
|||||||
extension Path {
|
extension Path {
|
||||||
//MARK: Common Directories
|
//MARK: Common Directories
|
||||||
|
|
||||||
/// Returns a `Path` containing ``FileManager.default.currentDirectoryPath`.
|
/// Returns a `Path` containing `FileManager.default.currentDirectoryPath`.
|
||||||
public static var cwd: Path {
|
public static var cwd: Path {
|
||||||
return Path(string: FileManager.default.currentDirectoryPath)
|
return Path(string: FileManager.default.currentDirectoryPath)
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ extension Path {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
The root for cache files.
|
The root for cache files.
|
||||||
- Note: On Linux this is 'XDG_CACHE_HOME'.
|
- Note: On Linux this is `XDG_CACHE_HOME`.
|
||||||
- Note: You should create a subdirectory before creating any files.
|
- Note: You should create a subdirectory before creating any files.
|
||||||
*/
|
*/
|
||||||
public static var caches: Path {
|
public static var caches: Path {
|
||||||
|
|||||||
@@ -147,7 +147,6 @@ public extension Path {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the directory at this path.
|
Creates the directory at this path.
|
||||||
- Note: Does not create any intermediary directories.
|
|
||||||
- Parameter options: Specify `mkdir(.p)` to create intermediary directories.
|
- Parameter options: Specify `mkdir(.p)` to create intermediary directories.
|
||||||
- Note: We do not error if the directory already exists (even without `.p`)
|
- Note: We do not error if the directory already exists (even without `.p`)
|
||||||
because *Path.swift* noops if the desired end result preexists.
|
because *Path.swift* noops if the desired end result preexists.
|
||||||
@@ -174,8 +173,8 @@ public extension Path {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Options for `Path.mkdir`
|
/// Options for `Path.mkdir(_:)`
|
||||||
public enum MakeDirectoryOptions {
|
public enum MakeDirectoryOptions {
|
||||||
/// Creates intermediary directories. Works the same as mkdir -p.
|
/// Creates intermediary directories; works the same as `mkdir -p`.
|
||||||
case p
|
case p
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
/**
|
||||||
|
A file entry from a directory listing.
|
||||||
|
- SeeAlso: `ls()`
|
||||||
|
*/
|
||||||
|
public struct Entry {
|
||||||
|
/// The kind of this directory entry.
|
||||||
|
public enum Kind {
|
||||||
|
/// The path is a file.
|
||||||
|
case file
|
||||||
|
/// The path is a directory.
|
||||||
|
case directory
|
||||||
|
}
|
||||||
|
/// The kind of this entry.
|
||||||
|
public let kind: Kind
|
||||||
|
/// The path of this entry.
|
||||||
|
public let path: Path
|
||||||
|
}
|
||||||
|
|
||||||
public extension Path {
|
public extension Path {
|
||||||
//MARK: Directory Listings
|
//MARK: Directory Listings
|
||||||
|
|
||||||
@@ -25,7 +43,7 @@ public extension Path {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience functions for the array return value of `Path.ls()`
|
/// Convenience functions for the array return value of `Path.ls()`
|
||||||
public extension Array where Element == Path.Entry {
|
public extension Array where Element == Entry {
|
||||||
/// Filters the list of entries to be a list of Paths that are directories.
|
/// Filters the list of entries to be a list of Paths that are directories.
|
||||||
var directories: [Path] {
|
var directories: [Path] {
|
||||||
return compactMap {
|
return compactMap {
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Represents a platform filesystem absolute path.
|
Represents a filesystem absolute path.
|
||||||
|
|
||||||
`Path` supports `Codable`, and can be configured to
|
`Path` supports `Codable`, and can be configured to
|
||||||
[encode paths *relatively*](https://github.com/mxcl/Path.swift/#codable).
|
[encode paths *relatively*](https://github.com/mxcl/Path.swift/#codable).
|
||||||
|
|
||||||
Sorting a `Sequence` of `Path`s will return the locale-aware sort order, which
|
Sorting a `Sequence` of `Path`s will return the locale-aware sort order, which
|
||||||
will give you the same order as Finder, (though folders will not be sorted
|
will give you the same order as Finder.
|
||||||
first).
|
|
||||||
|
All functions on `Path` are chainable and short to facilitate doing sequences
|
||||||
|
of file operations in a concise manner.
|
||||||
|
|
||||||
Converting from a `String` is a common first step, here are the recommended
|
Converting from a `String` is a common first step, here are the recommended
|
||||||
ways to do that:
|
ways to do that:
|
||||||
@@ -168,24 +170,4 @@ public struct Path: Equatable, Hashable, Comparable {
|
|||||||
public static func <(lhs: Path, rhs: Path) -> Bool {
|
public static func <(lhs: Path, rhs: Path) -> Bool {
|
||||||
return lhs.string.compare(rhs.string, locale: .current) == .orderedAscending
|
return lhs.string.compare(rhs.string, locale: .current) == .orderedAscending
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: Entry
|
|
||||||
|
|
||||||
/**
|
|
||||||
A file entry from a directory listing.
|
|
||||||
- SeeAlso: `ls()`
|
|
||||||
*/
|
|
||||||
public struct Entry {
|
|
||||||
/// The kind of this directory entry.
|
|
||||||
public enum Kind {
|
|
||||||
/// The path is a file.
|
|
||||||
case file
|
|
||||||
/// The path is a directory.
|
|
||||||
case directory
|
|
||||||
}
|
|
||||||
/// The kind of this entry.
|
|
||||||
public let kind: Kind
|
|
||||||
/// The path of this entry.
|
|
||||||
public let path: Path
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user