Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cc2fcbf30 | ||
|
|
7595c601e8 | ||
|
|
d8ea357459 |
11
.travis.yml
11
.travis.yml
@@ -47,13 +47,22 @@ jobs:
|
|||||||
- <<: *xcodebuild
|
- <<: *xcodebuild
|
||||||
stage: deploy
|
stage: deploy
|
||||||
name: Jazzy
|
name: Jazzy
|
||||||
|
before_install: |
|
||||||
|
cat << EOF > .jazzy.yml
|
||||||
|
custom_categories:
|
||||||
|
- name: Path
|
||||||
|
children:
|
||||||
|
- Path
|
||||||
|
- /(_:_:)
|
||||||
|
EOF
|
||||||
|
touch Contents.md
|
||||||
install: gem install jazzy
|
install: gem install jazzy
|
||||||
script: |
|
script: |
|
||||||
jazzy \
|
jazzy \
|
||||||
--no-hide-documentation-coverage \
|
--no-hide-documentation-coverage \
|
||||||
--theme fullwidth \
|
--theme fullwidth \
|
||||||
--output output \
|
--output output \
|
||||||
--readme README.md \
|
--readme Contents.md \
|
||||||
--root-url https://mxcl.github.io/Path.swift/ \
|
--root-url https://mxcl.github.io/Path.swift/ \
|
||||||
--github_url https://github.com/mxcl/Path.swift \
|
--github_url https://github.com/mxcl/Path.swift \
|
||||||
--module Path \
|
--module Path \
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'Path.swift'
|
s.name = 'Path.swift'
|
||||||
s.version = '0.4.0'
|
s.version = '0.4.1'
|
||||||
s.summary = 'Delightful, robust file-pathing functions'
|
s.summary = 'Delightful, robust file-pathing functions'
|
||||||
s.homepage = 'https://github.com/mxcl/Path.swift'
|
s.homepage = 'https://github.com/mxcl/Path.swift'
|
||||||
s.license = { :type => 'Unlicense', :file => 'LICENSE.md' }
|
s.license = { :type => 'Unlicense', :file => 'LICENSE.md' }
|
||||||
|
|||||||
@@ -183,13 +183,13 @@ Path("~foo") // => nil
|
|||||||
SwiftPM:
|
SwiftPM:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
package.append(.package(url: "https://github.com/mxcl/Path.swift", from: "0.4.0"))
|
package.append(.package(url: "https://github.com/mxcl/Path.swift", from: "0.4.1"))
|
||||||
```
|
```
|
||||||
|
|
||||||
CocoaPods:
|
CocoaPods:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
pod 'Path.swift' ~> 0.4.0
|
pod 'Path.swift' ~> '0.4.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
Please note! We are pre 1.0, thus we can change the API as we like! We will tag
|
Please note! We are pre 1.0, thus we can change the API as we like! We will tag
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public extension Path {
|
public extension Path {
|
||||||
/// same as the `ls` command ∴ is ”shallow”
|
/// Same as the `ls` command ∴ is ”shallow”
|
||||||
func ls() throws -> [Entry] {
|
/// - Parameter skipHiddenFiles: Same as the `ls -a` if false. Otherwise returns only the non hidden files. Default is false.
|
||||||
let relativePaths = try FileManager.default.contentsOfDirectory(atPath: string)
|
func ls(skipHiddenFiles: Bool = false) throws -> [Entry] {
|
||||||
func convert(relativePath: String) -> Entry {
|
let options: FileManager.DirectoryEnumerationOptions = skipHiddenFiles ? [.skipsHiddenFiles] : []
|
||||||
let path = self/relativePath
|
let paths = try FileManager.default.contentsOfDirectory(at: url,
|
||||||
|
includingPropertiesForKeys: nil,
|
||||||
|
options: options)
|
||||||
|
func convert(url: URL) -> Entry? {
|
||||||
|
guard let path = Path(url.path) else { return nil }
|
||||||
return Entry(kind: path.isDirectory ? .directory : .file, path: path)
|
return Entry(kind: path.isDirectory ? .directory : .file, path: path)
|
||||||
}
|
}
|
||||||
return relativePaths.map(convert)
|
return paths.compactMap(convert)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class PathTests: XCTestCase {
|
|||||||
try tmpdir.join("a").mkdir().join("c").touch()
|
try tmpdir.join("a").mkdir().join("c").touch()
|
||||||
try tmpdir.join("b").touch()
|
try tmpdir.join("b").touch()
|
||||||
try tmpdir.join("c").touch()
|
try tmpdir.join("c").touch()
|
||||||
|
try tmpdir.join(".d").mkdir().join("e").touch()
|
||||||
|
|
||||||
var paths = Set<String>()
|
var paths = Set<String>()
|
||||||
var dirs = 0
|
var dirs = 0
|
||||||
@@ -26,8 +27,30 @@ class PathTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
paths.insert(entry.path.basename())
|
paths.insert(entry.path.basename())
|
||||||
}
|
}
|
||||||
|
XCTAssertEqual(dirs, 2)
|
||||||
|
XCTAssertEqual(paths, ["a", "b", "c", ".d"])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEnumerationSkippingHiddenFiles() throws {
|
||||||
|
let tmpdir_ = try TemporaryDirectory()
|
||||||
|
let tmpdir = tmpdir_.path
|
||||||
|
try tmpdir.join("a").mkdir().join("c").touch()
|
||||||
|
try tmpdir.join("b").touch()
|
||||||
|
try tmpdir.join("c").touch()
|
||||||
|
try tmpdir.join(".d").mkdir().join("e").touch()
|
||||||
|
|
||||||
|
var paths = Set<String>()
|
||||||
|
var dirs = 0
|
||||||
|
for entry in try tmpdir.ls(skipHiddenFiles: true) {
|
||||||
|
if entry.kind == .directory {
|
||||||
|
dirs += 1
|
||||||
|
}
|
||||||
|
paths.insert(entry.path.basename())
|
||||||
|
}
|
||||||
XCTAssertEqual(dirs, 1)
|
XCTAssertEqual(dirs, 1)
|
||||||
XCTAssertEqual(paths, ["a", "b", "c"])
|
XCTAssertEqual(paths, ["a", "b", "c"])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRelativeTo() {
|
func testRelativeTo() {
|
||||||
|
|||||||
Reference in New Issue
Block a user