Compare commits

..

3 Commits
0.4.0 ... 0.4.1

Author SHA1 Message Date
Max Howell
5cc2fcbf30 Tag 0.4.1 2019-01-20 16:26:22 -05:00
Max Howell
7595c601e8 Attempt custom Jazzy index/contents 2019-01-20 16:24:06 -05:00
Luciano Almeida
d8ea357459 Adding ls -a like functionality to Path.ls() 2019-01-20 16:23:40 -05:00
5 changed files with 46 additions and 10 deletions

View File

@@ -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 \

View File

@@ -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' }

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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() {