-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Seidl
committed
Feb 17, 2018
1 parent
cc3ee97
commit 88c3a69
Showing
3 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Pathutil is I/O utility primary inspired by David Golden's [Path::Tiny](https://metacpan.org/pod/Path::Tiny). | ||
It is friendlier to use than [path](https://golang.org/pkg/path/), [filepath](https://golang.org/pkg/path/filepath/) | ||
and provides many of other functions which isn't in core libraries (like `Copy` for example) | ||
SYNOPSIS | ||
import ( | ||
"fmt" | ||
"github.com/JaSei/pathutil-go" | ||
) | ||
// creating pathutil objects | ||
dir, _ := pathutil.New("/tmp") | ||
foo, _ := pathutil.New("foo.txt") | ||
subdir, _ := dir.Child("foo") | ||
bar, _ := subdir.Child("bar.txt") | ||
// stringifies as cleaned up path | ||
file, _ := pathutil.New("./foo.txt") | ||
fmt.Println(file) // "foo.txt" | ||
// reading files | ||
guts, _ := file.Slurp() | ||
lines, _ := file.Lines() | ||
// writing files | ||
bar.Spew(data) | ||
// reading directories | ||
children, _ := dir.Children() | ||
for _, child := range children { | ||
} | ||
SEE ALSO | ||
* [Path::Tiny](https://metacpan.org/pod/Path::Tiny) for Perl | ||
* [better files](https://github.com/pathikrit/better-files) for Scala | ||
* [pathlib](https://docs.python.org/3/library/pathlib.html) for python | ||
*/ | ||
package pathutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pathutil_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/JaSei/pathutil-go" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSynopsis(t *testing.T) { | ||
// creating pathutil objects | ||
dir, _ := pathutil.New("/tmp") | ||
//foo, _ := pathutil.New("foo.txt") | ||
|
||
subdir, _ := dir.Child("foo") | ||
assert.Equal(t, "/tmp/foo", subdir.String()) | ||
bar, _ := subdir.Child("bar.txt") | ||
assert.Equal(t, "/tmp/foo/bar.txt", bar.String()) | ||
|
||
file, _ := pathutil.New("./foo.txt") | ||
assert.Equal(t, "foo.txt", file.String()) | ||
fmt.Println(file) | ||
|
||
// reading files | ||
guts, _ := file.Slurp() | ||
assert.Empty(t, guts) | ||
lines, _ := file.Lines() | ||
assert.Empty(t, lines) | ||
|
||
// writing files | ||
_ = bar.Spew("ahoj") | ||
|
||
// reading directories | ||
children, _ := dir.Children() | ||
for _, child := range children { | ||
fmt.Println(child) | ||
} | ||
} |