a self-made mug is hard to break

This commit is contained in:
Mark Bates 2019-10-31 11:12:18 -04:00
parent 5c07a3dede
commit d41fe52ef2
10 changed files with 3 additions and 107 deletions

View File

@ -33,8 +33,6 @@ Pkger's API is modeled on that of the [`os`](https://godoc.org/os) package in Go
```go ```go
type Pkger interface { type Pkger interface {
Parse(p string) (Path, error) Parse(p string) (Path, error)
Abs(p string) (string, error)
AbsPath(Path) (string, error)
Current() (here.Info, error) Current() (here.Info, error)
Info(p string) (here.Info, error) Info(p string) (here.Info, error)
Create(name string) (File, error) Create(name string) (File, error)
@ -48,7 +46,6 @@ type Pkger interface {
type File interface { type File interface {
Close() error Close() error
Abs() (string, error)
Info() here.Info Info() here.Info
Name() string Name() string
Open(name string) (http.File, error) Open(name string) (http.File, error)

View File

@ -10,11 +10,8 @@ jobs:
vmImage: "vs2017-win2016" vmImage: "vs2017-win2016"
strategy: strategy:
matrix: matrix:
go 1.12 (on):
go_version: "1.12.9"
GO111MODULE: "on"
go 1.13 (on): go 1.13 (on):
go_version: "1.13" go_version: "1.13.3"
GO111MODULE: "on" GO111MODULE: "on"
steps: steps:
- template: azure-tests.yml - template: azure-tests.yml
@ -24,11 +21,8 @@ jobs:
vmImage: "macOS-10.13" vmImage: "macOS-10.13"
strategy: strategy:
matrix: matrix:
go 1.12 (on):
go_version: "1.12.9"
GO111MODULE: "on"
go 1.13 (on): go 1.13 (on):
go_version: "1.13" go_version: "1.13.3"
GO111MODULE: "on" GO111MODULE: "on"
steps: steps:
- template: azure-tests.yml - template: azure-tests.yml
@ -38,11 +32,8 @@ jobs:
vmImage: "ubuntu-16.04" vmImage: "ubuntu-16.04"
strategy: strategy:
matrix: matrix:
go 1.12 (on):
go_version: "1.12.9"
GO111MODULE: "on"
go 1.13 (on): go 1.13 (on):
go_version: "1.13" go_version: "1.13.3"
GO111MODULE: "on" GO111MODULE: "on"
steps: steps:
- template: azure-tests.yml - template: azure-tests.yml

View File

@ -51,16 +51,6 @@ func Parse(p string) (here.Path, error) {
return impl().Parse(p) return impl().Parse(p)
} }
// Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func Abs(p string) (string, error) {
return impl().Abs(p)
}
// AbsPath returns an absolute representation of here.Path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. AbsPath calls Clean on the result.
func AbsPath(p here.Path) (string, error) {
return impl().AbsPath(p)
}
// Current returns the here.Info representing the current Pkger implementation. // Current returns the here.Info representing the current Pkger implementation.
func Current() (here.Info, error) { func Current() (here.Info, error) {
return impl().Current() return impl().Current()

View File

@ -2,10 +2,8 @@ package pkger
import ( import (
"os" "os"
"path/filepath"
"testing" "testing"
"github.com/markbates/pkger/here"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -18,31 +16,6 @@ func Test_Parse(t *testing.T) {
r.Equal("/little", pt.Name) r.Equal("/little", pt.Name)
} }
func Test_Abs(t *testing.T) {
r := require.New(t)
s, err := Abs(":/rocket.ship")
r.NoError(err)
pwd, err := os.Getwd()
r.NoError(err)
r.Equal(filepath.Join(pwd, "rocket.ship"), s)
}
func Test_AbsPath(t *testing.T) {
r := require.New(t)
s, err := AbsPath(here.Path{
Pkg: "github.com/markbates/pkger",
Name: "/rocket.ship",
})
r.NoError(err)
pwd, err := os.Getwd()
r.NoError(err)
r.Equal(filepath.Join(pwd, "rocket.ship"), s)
}
func Test_Current(t *testing.T) { func Test_Current(t *testing.T) {
r := require.New(t) r := require.New(t)

View File

@ -11,9 +11,6 @@ type File interface {
// Close closes the File, rendering it unusable for I/O. // Close closes the File, rendering it unusable for I/O.
Close() error Close() error
// Abs returns an absolute representation of the file. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
Abs() (string, error)
// Info returns the here.Info of the file // Info returns the here.Info of the file
Info() here.Info Info() here.Info

View File

@ -104,11 +104,6 @@ func (f File) Name() string {
return f.path.String() return f.path.String()
} }
// Abs returns an absolute representation of the file. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func (f File) Abs() (string, error) {
return f.pkging.AbsPath(f.Path())
}
// Path returns the here.Path of the file // Path returns the here.Path of the file
func (f File) Path() here.Path { func (f File) Path() here.Path {
return f.path return f.path

View File

@ -32,20 +32,6 @@ type Pkger struct {
files *maps.Files files *maps.Files
} }
// Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func (f *Pkger) Abs(p string) (string, error) {
pt, err := f.Parse(p)
if err != nil {
return "", err
}
return f.AbsPath(pt)
}
// AbsPath returns an absolute representation of here.Path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. AbsPath calls Clean on the result.
func (f *Pkger) AbsPath(pt here.Path) (string, error) {
return pt.String(), nil
}
// Current returns the here.Info representing the current Pkger implementation. // Current returns the here.Info representing the current Pkger implementation.
func (f *Pkger) Current() (here.Info, error) { func (f *Pkger) Current() (here.Info, error) {
return f.Here, nil return f.Here, nil

View File

@ -11,12 +11,6 @@ type Pkger interface {
// Parse the string in here.Path format. // Parse the string in here.Path format.
Parse(p string) (here.Path, error) Parse(p string) (here.Path, error)
// Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
Abs(p string) (string, error)
// AbsPath returns an absolute representation of here.Path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. AbsPath calls Clean on the result.
AbsPath(here.Path) (string, error)
// Current returns the here.Info representing the current Pkger implementation. // Current returns the here.Info representing the current Pkger implementation.
Current() (here.Info, error) Current() (here.Info, error)

View File

@ -24,11 +24,6 @@ func (f *File) Close() error {
return f.File.Close() return f.File.Close()
} }
// Abs returns an absolute representation of the file. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func (f *File) Abs() (string, error) {
return f.pkging.AbsPath(f.path)
}
// Info returns the here.Info of the file // Info returns the here.Info of the file
func (f *File) Info() here.Info { func (f *File) Info() here.Info {
return f.her return f.her

View File

@ -38,28 +38,6 @@ func (w withPkger) Parse(p string) (here.Path, error) {
return pt, nil return pt, nil
} }
func (w withPkger) Abs(p string) (string, error) {
pt, err := w.base.Abs(p)
if err != nil {
if w.parent != nil {
return w.parent.Abs(p)
}
return pt, err
}
return pt, nil
}
func (w withPkger) AbsPath(p here.Path) (string, error) {
pt, err := w.base.AbsPath(p)
if err != nil {
if w.parent != nil {
return w.parent.AbsPath(p)
}
return pt, err
}
return pt, nil
}
func (w withPkger) Current() (here.Info, error) { func (w withPkger) Current() (here.Info, error) {
pt, err := w.base.Current() pt, err := w.base.Current()
if err != nil { if err != nil {