Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cc2fcbf30 | ||
|
|
7595c601e8 | ||
|
|
d8ea357459 |
11
.travis.yml
11
.travis.yml
@@ -47,13 +47,22 @@ jobs:
|
||||
- <<: *xcodebuild
|
||||
stage: deploy
|
||||
name: Jazzy
|
||||
before_install: |
|
||||
cat << EOF > .jazzy.yml
|
||||
custom_categories:
|
||||
- name: Path
|
||||
children:
|
||||
- Path
|
||||
- /(_:_:)
|
||||
EOF
|
||||
touch Contents.md
|
||||
install: gem install jazzy
|
||||
script: |
|
||||
jazzy \
|
||||
--no-hide-documentation-coverage \
|
||||
--theme fullwidth \
|
||||
--output output \
|
||||
--readme README.md \
|
||||
--readme Contents.md \
|
||||
--root-url https://mxcl.github.io/Path.swift/ \
|
||||
--github_url https://github.com/mxcl/Path.swift \
|
||||
--module Path \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'Path.swift'
|
||||
s.version = '0.4.0'
|
||||
s.version = '0.4.1'
|
||||
s.summary = 'Delightful, robust file-pathing functions'
|
||||
s.homepage = 'https://github.com/mxcl/Path.swift'
|
||||
s.license = { :type => 'Unlicense', :file => 'LICENSE.md' }
|
||||
|
||||
@@ -183,13 +183,13 @@ Path("~foo") // => nil
|
||||
SwiftPM:
|
||||
|
||||
```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:
|
||||
|
||||
```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
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import Foundation
|
||||
|
||||
public extension Path {
|
||||
/// same as the `ls` command ∴ is ”shallow”
|
||||
func ls() throws -> [Entry] {
|
||||
let relativePaths = try FileManager.default.contentsOfDirectory(atPath: string)
|
||||
func convert(relativePath: String) -> Entry {
|
||||
let path = self/relativePath
|
||||
/// Same as the `ls` command ∴ is ”shallow”
|
||||
/// - Parameter skipHiddenFiles: Same as the `ls -a` if false. Otherwise returns only the non hidden files. Default is false.
|
||||
func ls(skipHiddenFiles: Bool = false) throws -> [Entry] {
|
||||
let options: FileManager.DirectoryEnumerationOptions = skipHiddenFiles ? [.skipsHiddenFiles] : []
|
||||
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 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("b").touch()
|
||||
try tmpdir.join("c").touch()
|
||||
try tmpdir.join(".d").mkdir().join("e").touch()
|
||||
|
||||
var paths = Set<String>()
|
||||
var dirs = 0
|
||||
@@ -26,8 +27,30 @@ class PathTests: XCTestCase {
|
||||
}
|
||||
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(paths, ["a", "b", "c"])
|
||||
|
||||
}
|
||||
|
||||
func testRelativeTo() {
|
||||
|
||||
Reference in New Issue
Block a user