File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,20 +26,40 @@ type Path struct {
2626 Sep string
2727}
2828
29- // NewPath returns a new OS path
30- func NewPath (path string ) * Path {
31- return NewPathAfero (path , afero .NewOsFs ())
29+ type PathOpts func (p * Path )
30+
31+ func PathWithAfero (fs afero.Fs ) PathOpts {
32+ return func (p * Path ) {
33+ p .fs = fs
34+ }
3235}
3336
34- // NewPathAfero returns a Path object with the given Afero object
35- func NewPathAfero (path string , fs afero.Fs ) * Path {
36- return & Path {
37+ func PathWithSeperator (sep string ) PathOpts {
38+ return func (p * Path ) {
39+ p .Sep = sep
40+ }
41+ }
42+
43+ // NewPath returns a new OS path
44+ func NewPath (path string , opts ... PathOpts ) * Path {
45+ p := & Path {
3746 path : path ,
38- fs : fs ,
47+ fs : afero . NewOsFs () ,
3948 DefaultFileMode : DefaultFileMode ,
4049 DefaultDirMode : DefaultDirMode ,
4150 Sep : string (os .PathSeparator ),
4251 }
52+ for _ , opt := range opts {
53+ opt (p )
54+ }
55+ return p
56+ }
57+
58+ // NewPathAfero returns a Path object with the given Afero object
59+ //
60+ // Deprecated: Use the PathWithAfero option in Newpath instead.
61+ func NewPathAfero (path string , fs afero.Fs ) * Path {
62+ return NewPath (path , PathWithAfero (fs ))
4363}
4464
4565// Glob returns all of the path objects matched by the given pattern
You can’t perform that action at this time.
0 commit comments