Skip to content

Commit

Permalink
doc.go, fix list of SEE ALSO
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Seidl committed Feb 17, 2018
1 parent cc3ee97 commit 88c3a69
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pathutil

[![Release](https://img.shields.io/github/release/JaSei/pathutil-go.svg?style=flat-square)](https://github.com/JaSei/pathutil-go/releases/latest)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Travis](https://img.shields.io/travis/JaSei/pathutil-go.svg?style=flat-square)](https://travis-ci.org/JaSei/pathutil-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/JaSei/pathutil-go?style=flat-square)](https://goreportcard.com/report/github.com/JaSei/pathutil-go)
[![GoDoc](https://godoc.org/github.com/JaSei/pathutil-go?status.svg&style=flat-square)](http://godoc.org/github.com/JaSei/pathutil-go)
Expand Down Expand Up @@ -47,9 +47,11 @@ functions which isn't in core libraries (like `Copy` for example)

### 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
* [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

## Usage

Expand Down
45 changes: 45 additions & 0 deletions doc.go
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
39 changes: 39 additions & 0 deletions examples/synopsis_test.go
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)
}
}

0 comments on commit 88c3a69

Please sign in to comment.