forked from mirror/pkger
a self-made mug is hard to break
This commit is contained in:
parent
5c07a3dede
commit
d41fe52ef2
|
@ -33,8 +33,6 @@ Pkger's API is modeled on that of the [`os`](https://godoc.org/os) package in Go
|
|||
```go
|
||||
type Pkger interface {
|
||||
Parse(p string) (Path, error)
|
||||
Abs(p string) (string, error)
|
||||
AbsPath(Path) (string, error)
|
||||
Current() (here.Info, error)
|
||||
Info(p string) (here.Info, error)
|
||||
Create(name string) (File, error)
|
||||
|
@ -48,7 +46,6 @@ type Pkger interface {
|
|||
|
||||
type File interface {
|
||||
Close() error
|
||||
Abs() (string, error)
|
||||
Info() here.Info
|
||||
Name() string
|
||||
Open(name string) (http.File, error)
|
||||
|
|
|
@ -10,11 +10,8 @@ jobs:
|
|||
vmImage: "vs2017-win2016"
|
||||
strategy:
|
||||
matrix:
|
||||
go 1.12 (on):
|
||||
go_version: "1.12.9"
|
||||
GO111MODULE: "on"
|
||||
go 1.13 (on):
|
||||
go_version: "1.13"
|
||||
go_version: "1.13.3"
|
||||
GO111MODULE: "on"
|
||||
steps:
|
||||
- template: azure-tests.yml
|
||||
|
@ -24,11 +21,8 @@ jobs:
|
|||
vmImage: "macOS-10.13"
|
||||
strategy:
|
||||
matrix:
|
||||
go 1.12 (on):
|
||||
go_version: "1.12.9"
|
||||
GO111MODULE: "on"
|
||||
go 1.13 (on):
|
||||
go_version: "1.13"
|
||||
go_version: "1.13.3"
|
||||
GO111MODULE: "on"
|
||||
steps:
|
||||
- template: azure-tests.yml
|
||||
|
@ -38,11 +32,8 @@ jobs:
|
|||
vmImage: "ubuntu-16.04"
|
||||
strategy:
|
||||
matrix:
|
||||
go 1.12 (on):
|
||||
go_version: "1.12.9"
|
||||
GO111MODULE: "on"
|
||||
go 1.13 (on):
|
||||
go_version: "1.13"
|
||||
go_version: "1.13.3"
|
||||
GO111MODULE: "on"
|
||||
steps:
|
||||
- template: azure-tests.yml
|
||||
|
|
10
pkger.go
10
pkger.go
|
@ -51,16 +51,6 @@ func Parse(p string) (here.Path, error) {
|
|||
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.
|
||||
func Current() (here.Info, error) {
|
||||
return impl().Current()
|
||||
|
|
|
@ -2,10 +2,8 @@ package pkger
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -18,31 +16,6 @@ func Test_Parse(t *testing.T) {
|
|||
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) {
|
||||
r := require.New(t)
|
||||
|
||||
|
|
|
@ -11,9 +11,6 @@ type File interface {
|
|||
// Close closes the File, rendering it unusable for I/O.
|
||||
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() here.Info
|
||||
|
||||
|
|
|
@ -104,11 +104,6 @@ func (f File) Name() 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
|
||||
func (f File) Path() here.Path {
|
||||
return f.path
|
||||
|
|
|
@ -32,20 +32,6 @@ type Pkger struct {
|
|||
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.
|
||||
func (f *Pkger) Current() (here.Info, error) {
|
||||
return f.Here, nil
|
||||
|
|
|
@ -11,12 +11,6 @@ type Pkger interface {
|
|||
// Parse the string in here.Path format.
|
||||
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() (here.Info, error)
|
||||
|
||||
|
|
|
@ -24,11 +24,6 @@ func (f *File) Close() error {
|
|||
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
|
||||
func (f *File) Info() here.Info {
|
||||
return f.her
|
||||
|
|
|
@ -38,28 +38,6 @@ func (w withPkger) Parse(p string) (here.Path, error) {
|
|||
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) {
|
||||
pt, err := w.base.Current()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue