Skip to content

Commit 1fcd15d

Browse files
committed
Updated the getting started section.
1 parent 55c8182 commit 1fcd15d

File tree

6 files changed

+100
-52
lines changed

6 files changed

+100
-52
lines changed

README.md

Lines changed: 91 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,76 +15,118 @@ julia> Pkg.add("FilePathsBase")
1515
```
1616

1717
## Getting Started
18-
```julia
19-
julia> using FilePathsBase; using FilePathsBase: /
20-
```
2118

22-
The first important difference about working with paths in FilePathsBase.jl is that path
23-
segments are represented as an immutable tuple of strings.
19+
Here are some common operations that you may want to perform with file paths.
2420

25-
Path creation:
2621
```julia
27-
julia> Path("~/repos/FilePathsBase.jl/")
28-
p"~/repos/FilePathsBase.jl/"
29-
```
30-
or
31-
```julia
32-
julia> p"~/repos/FilePathsBase.jl/"
33-
p"~/repos/FilePathsBase.jl/"
34-
```
22+
#=
23+
NOTE: We're loading our `/` operator for path concatenation into the currect scope, but non-path division operations will still fallback to the base behaviour.
24+
=#
25+
julia> using FilePathsBase; using FilePathsBase: /
3526

36-
Human readable file status info:
37-
```julia
38-
julia> stat(p"README.md")
27+
julia> cwd()
28+
p"/Users/rory/repos/FilePathsBase.jl"
29+
30+
julia> walkpath(cwd() / "docs") |> collect
31+
23-element Array{Any,1}:
32+
p"/Users/rory/repos/FilePathsBase.jl/docs/.DS_Store"
33+
p"/Users/rory/repos/FilePathsBase.jl/docs/Manifest.toml"
34+
p"/Users/rory/repos/FilePathsBase.jl/docs/Project.toml"
35+
p"/Users/rory/repos/FilePathsBase.jl/docs/build"
36+
p"/Users/rory/repos/FilePathsBase.jl/docs/build/api.html"
37+
p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets"
38+
p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets/arrow.svg"
39+
p"/Users/rory/repos/FilePathsBase.jl/docs/build/assets/documenter.css"
40+
...
41+
42+
julia> stat(p"docs/src/index.md")
3943
Status(
40-
device = 16777220,
41-
inode = 48428965,
44+
device = 16777223,
45+
inode = 32240108,
4246
mode = -rw-r--r--,
4347
nlink = 1,
44-
uid = 501,
45-
gid = 20,
48+
uid = 501 (rory),
49+
gid = 20 (staff),
4650
rdev = 0,
47-
size = 1880 (1.8K),
51+
size = 2028 (2.0K),
4852
blksize = 4096 (4.0K),
4953
blocks = 8,
50-
mtime = 2016-02-16T00:49:27,
51-
ctime = 2016-02-16T00:49:27,
54+
mtime = 2020-04-20T17:20:38.612,
55+
ctime = 2020-04-20T17:20:38.612,
5256
)
53-
```
5457

55-
Working with permissions:
56-
```julia
57-
julia> m = mode(p"README.md")
58-
-rw-r--r--
58+
julia> relative(p"docs/src/index.md", p"src/")
59+
p"../docs/src/index.md"
5960

60-
julia> m - readable(:ALL)
61-
--w-------
61+
julia> normalize(p"src/../docs/src/index.md")
62+
p"docs/src/index.md"
6263

63-
julia> m + executable(:ALL)
64-
-rwxr-xr-x
64+
julia> absolute(p"docs/src/index.md")
65+
p"/Users/rory/repos/FilePathsBase.jl/docs/src/index.md"
6566

66-
julia> chmod(p"README.md", "+x")
67+
julia> islink(p"docs/src/index.md")
68+
true
6769

68-
julia> mode(p"README.md")
69-
-rwxr-xr-x
70+
julia> canonicalize(p"docs/src/index.md")
71+
p"/Users/rory/repos/FilePathsBase.jl/README.md"
7072

71-
julia> chmod(p"README.md", m)
73+
julia> parents(p"./docs/src")
74+
2-element Array{PosixPath,1}:
75+
p"."
76+
p"./docs"
7277

73-
julia> m = mode(p"README.md")
74-
-rw-r--r--
78+
julia> parents(absolute(p"./docs/src"))
79+
6-element Array{PosixPath,1}:
80+
p"/"
81+
p"/Users"
82+
p"/Users/rory"
83+
p"/Users/rory/repos"
84+
p"/Users/rory/repos/FilePathsBase.jl"
85+
p"/Users/rory/repos/FilePathsBase.jl/docs"
7586

76-
julia> chmod(p"README.md", user=(READ+WRITE+EXEC), group=(READ+WRITE), other=READ)
87+
julia> absolute(p"./docs/src")[1:end-1]
88+
("Users", "rory", "repos", "FilePathsBase.jl", "docs")
7789

78-
julia> mode(p"README.md")
79-
-rwxrw-r--
90+
julia> tmpfp = mktempdir(SystemPath)
91+
p"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT"
8092

81-
```
93+
julia> sync(p"/Users/rory/repos/FilePathsBase.jl/docs", tmpfp / "docs")
94+
p"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT/docs"
8295

83-
Reading and writing directly to file paths:
84-
```julia
85-
julia> write(p"testfile", "foobar")
86-
6
96+
julia> exists(tmpfp / "docs" / "make.jl")
97+
true
98+
99+
julia> m = mode(tmpfp / "docs" / "make.jl")
100+
Mode("-rw-r--r--")
101+
102+
julia> m - readable(:ALL)
103+
Mode("--w-------")
104+
105+
julia> m + executable(:ALL)
106+
Mode("-rwxr-xr-x")
107+
108+
julia> chmod(tmpfp / "docs" / "make.jl", "+x")
109+
"/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/jl_1GCBFT/docs/make.jl"
110+
111+
julia> mode(tmpfp / "docs" / "make.jl")
112+
Mode("-rwxr-xr-x")
113+
114+
# Count LOC
115+
julia> mapreduce(+, walkpath(cwd() / "src")) do x
116+
extension(x) == "jl" ? count("\n", read(x, String)) : 0
117+
end
118+
3020
119+
120+
# Concatenate multiple files.
121+
julia> str = mapreduce(*, walkpath(tmpfp / "docs" / "src")) do x
122+
read(x, String)
123+
end
124+
"# API\n\nAll the standard methods for working with paths in base julia exist in the FilePathsBase.jl. The following describes the rough mapping of method names. Use `?` at the REPL to get the documentation and arguments as they may be different than the base implementations.\n\n..."
125+
126+
# Could also write the result to a file with `write(newfile, str)`)
127+
128+
julia> rm(tmpfp; recursive=true)
87129

88-
julia> read(p"testfile")
89-
"foobar"
130+
julia> exists(tmpfp)
131+
false
90132
```

docs/.DS_Store

0 Bytes
Binary file not shown.

docs/make.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
using Documenter, FilePathsBase, FilePathsBase.TestPaths
22

3+
```@meta
4+
DocTestSetup = quote
5+
using FilePathsBase; using FilePathsBase: /, join;
6+
end
7+
```
8+
39
makedocs(
410
modules=[FilePathsBase],
511
format=Documenter.HTML(

docs/src/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Background
1+
# [Design](@id design_header)
22

33
FilePaths.jl and FilePathsBase.jl have gone through several design iterations over the years.
44
To help get potential contributors up-to-speed, we'll cover several background points and design choices.

docs/src/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Some cases where the path type distinction is useful include:
1818
- Path specific operations (e.g., `join`, `/`, `==`)
1919
- Dispatch on paths vs strings (e.g., `project(name::String) = project(DEFAULT_ROOT / name)`)
2020

21-
See [background section] for more details on the advantages of path types over strings.
21+
See [design section](@ref design_header) for more details on the advantages of path types over strings.
2222

2323
**Q. Why is `AbstractPath` not a subtype of `AbstractString`?
2424

src/path.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ p"foo/bar/baz"
272272
Joins path components into a full path.
273273
274274
# Example
275-
```jldoctest
275+
```jldoctest; setup = :(using FilePathsBase: /, join)
276276
julia> join(p"~/.julia/v0.6", "REQUIRE")
277277
p"~/.julia/v0.6/REQUIRE"
278278
```

0 commit comments

Comments
 (0)