From d47bad9071880e40505ab7d56caf0cfa57a49f28 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Thu, 1 May 2025 18:13:51 +0000 Subject: [PATCH] feat: unexport all node implementation fields --- taskfile/node_base.go | 16 ++++++++-------- taskfile/node_cache.go | 4 ++-- taskfile/node_file.go | 14 +++++++------- taskfile/node_git.go | 14 +++++++------- taskfile/node_git_test.go | 8 ++++---- taskfile/node_http.go | 4 ++-- taskfile/node_stdin.go | 4 ++-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/taskfile/node_base.go b/taskfile/node_base.go index 8dd60f83..c712de6c 100644 --- a/taskfile/node_base.go +++ b/taskfile/node_base.go @@ -1,19 +1,19 @@ package taskfile type ( - NodeOption func(*BaseNode) - // BaseNode is a generic node that implements the Parent() methods of the + NodeOption func(*baseNode) + // baseNode is a generic node that implements the Parent() methods of the // NodeReader interface. It does not implement the Read() method and it // designed to be embedded in other node types so that this boilerplate code // does not need to be repeated. - BaseNode struct { + baseNode struct { parent Node dir string } ) -func NewBaseNode(dir string, opts ...NodeOption) *BaseNode { - node := &BaseNode{ +func NewBaseNode(dir string, opts ...NodeOption) *baseNode { + node := &baseNode{ parent: nil, dir: dir, } @@ -27,15 +27,15 @@ func NewBaseNode(dir string, opts ...NodeOption) *BaseNode { } func WithParent(parent Node) NodeOption { - return func(node *BaseNode) { + return func(node *baseNode) { node.parent = parent } } -func (node *BaseNode) Parent() Node { +func (node *baseNode) Parent() Node { return node.parent } -func (node *BaseNode) Dir() string { +func (node *baseNode) Dir() string { return node.dir } diff --git a/taskfile/node_cache.go b/taskfile/node_cache.go index b489161b..0dac8114 100644 --- a/taskfile/node_cache.go +++ b/taskfile/node_cache.go @@ -11,13 +11,13 @@ import ( const remoteCacheDir = "remote" type CacheNode struct { - *BaseNode + *baseNode source RemoteNode } func NewCacheNode(source RemoteNode, dir string) *CacheNode { return &CacheNode{ - BaseNode: &BaseNode{ + baseNode: &baseNode{ dir: filepath.Join(dir, remoteCacheDir), }, source: source, diff --git a/taskfile/node_file.go b/taskfile/node_file.go index 79b7a957..aa35437c 100644 --- a/taskfile/node_file.go +++ b/taskfile/node_file.go @@ -13,8 +13,8 @@ import ( // A FileNode is a node that reads a taskfile from the local filesystem. type FileNode struct { - *BaseNode - Entrypoint string + *baseNode + entrypoint string } func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error) { @@ -25,13 +25,13 @@ func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error) return nil, err } return &FileNode{ - BaseNode: base, - Entrypoint: entrypoint, + baseNode: base, + entrypoint: entrypoint, }, nil } func (node *FileNode) Location() string { - return node.Entrypoint + return node.entrypoint } func (node *FileNode) Read() ([]byte, error) { @@ -63,7 +63,7 @@ func (node *FileNode) ResolveEntrypoint(entrypoint string) (string, error) { // NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory // This means that files are included relative to one another - entrypointDir := filepath.Dir(node.Entrypoint) + entrypointDir := filepath.Dir(node.entrypoint) return filepathext.SmartJoin(entrypointDir, path), nil } @@ -79,6 +79,6 @@ func (node *FileNode) ResolveDir(dir string) (string, error) { // NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory // This means that files are included relative to one another - entrypointDir := filepath.Dir(node.Entrypoint) + entrypointDir := filepath.Dir(node.entrypoint) return filepathext.SmartJoin(entrypointDir, path), nil } diff --git a/taskfile/node_git.go b/taskfile/node_git.go index eb30a467..5152ea7e 100644 --- a/taskfile/node_git.go +++ b/taskfile/node_git.go @@ -21,8 +21,8 @@ import ( // An GitNode is a node that reads a Taskfile from a remote location via Git. type GitNode struct { - *BaseNode - URL *url.URL + *baseNode + url *url.URL rawUrl string ref string path string @@ -52,8 +52,8 @@ func NewGitNode( return nil, &errors.TaskfileNotSecureError{URI: u.Redacted()} } return &GitNode{ - BaseNode: base, - URL: u, + baseNode: base, + url: u, rawUrl: rawUrl, ref: ref, path: path, @@ -76,7 +76,7 @@ func (node *GitNode) ReadContext(_ context.Context) ([]byte, error) { fs := memfs.New() storer := memory.NewStorage() _, err := git.Clone(storer, fs, &git.CloneOptions{ - URL: node.URL.String(), + URL: node.url.String(), ReferenceName: plumbing.ReferenceName(node.ref), SingleBranch: true, Depth: 1, @@ -99,7 +99,7 @@ func (node *GitNode) ReadContext(_ context.Context) ([]byte, error) { func (node *GitNode) ResolveEntrypoint(entrypoint string) (string, error) { dir, _ := filepath.Split(node.path) - resolvedEntrypoint := fmt.Sprintf("%s//%s", node.URL, filepath.Join(dir, entrypoint)) + resolvedEntrypoint := fmt.Sprintf("%s//%s", node.url, filepath.Join(dir, entrypoint)) if node.ref != "" { return fmt.Sprintf("%s?ref=%s", resolvedEntrypoint, node.ref), nil } @@ -130,7 +130,7 @@ func (node *GitNode) CacheKey() string { if len(lastDir) > 1 { prefix = fmt.Sprintf("%s.%s", lastDir, prefix) } - return fmt.Sprintf("git.%s.%s.%s", node.URL.Host, prefix, checksum) + return fmt.Sprintf("git.%s.%s.%s", node.url.Host, prefix, checksum) } func splitURLOnDoubleSlash(u *url.URL) (string, string) { diff --git a/taskfile/node_git_test.go b/taskfile/node_git_test.go index 3f24bfd3..c359ae81 100644 --- a/taskfile/node_git_test.go +++ b/taskfile/node_git_test.go @@ -15,7 +15,7 @@ func TestGitNode_ssh(t *testing.T) { assert.Equal(t, "main", node.ref) assert.Equal(t, "Taskfile.yml", node.path) assert.Equal(t, "ssh://git@github.com/foo/bar.git//Taskfile.yml?ref=main", node.Location()) - assert.Equal(t, "ssh://git@github.com/foo/bar.git", node.URL.String()) + assert.Equal(t, "ssh://git@github.com/foo/bar.git", node.url.String()) entrypoint, err := node.ResolveEntrypoint("common.yml") assert.NoError(t, err) assert.Equal(t, "ssh://git@github.com/foo/bar.git//common.yml?ref=main", entrypoint) @@ -29,7 +29,7 @@ func TestGitNode_sshWithDir(t *testing.T) { assert.Equal(t, "main", node.ref) assert.Equal(t, "directory/Taskfile.yml", node.path) assert.Equal(t, "ssh://git@github.com/foo/bar.git//directory/Taskfile.yml?ref=main", node.Location()) - assert.Equal(t, "ssh://git@github.com/foo/bar.git", node.URL.String()) + assert.Equal(t, "ssh://git@github.com/foo/bar.git", node.url.String()) entrypoint, err := node.ResolveEntrypoint("common.yml") assert.NoError(t, err) assert.Equal(t, "ssh://git@github.com/foo/bar.git//directory/common.yml?ref=main", entrypoint) @@ -43,7 +43,7 @@ func TestGitNode_https(t *testing.T) { assert.Equal(t, "main", node.ref) assert.Equal(t, "Taskfile.yml", node.path) assert.Equal(t, "https://github.com/foo/bar.git//Taskfile.yml?ref=main", node.Location()) - assert.Equal(t, "https://github.com/foo/bar.git", node.URL.String()) + assert.Equal(t, "https://github.com/foo/bar.git", node.url.String()) entrypoint, err := node.ResolveEntrypoint("common.yml") assert.NoError(t, err) assert.Equal(t, "https://github.com/foo/bar.git//common.yml?ref=main", entrypoint) @@ -57,7 +57,7 @@ func TestGitNode_httpsWithDir(t *testing.T) { assert.Equal(t, "main", node.ref) assert.Equal(t, "directory/Taskfile.yml", node.path) assert.Equal(t, "https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", node.Location()) - assert.Equal(t, "https://github.com/foo/bar.git", node.URL.String()) + assert.Equal(t, "https://github.com/foo/bar.git", node.url.String()) entrypoint, err := node.ResolveEntrypoint("common.yml") assert.NoError(t, err) assert.Equal(t, "https://github.com/foo/bar.git//directory/common.yml?ref=main", entrypoint) diff --git a/taskfile/node_http.go b/taskfile/node_http.go index 2fda740d..ca0d75af 100644 --- a/taskfile/node_http.go +++ b/taskfile/node_http.go @@ -16,7 +16,7 @@ import ( // An HTTPNode is a node that reads a Taskfile from a remote location via HTTP. type HTTPNode struct { - *BaseNode + *baseNode URL *url.URL // stores url pointing actual remote file. (e.g. with Taskfile.yml) } @@ -35,7 +35,7 @@ func NewHTTPNode( return nil, &errors.TaskfileNotSecureError{URI: url.Redacted()} } return &HTTPNode{ - BaseNode: base, + baseNode: base, URL: url, }, nil } diff --git a/taskfile/node_stdin.go b/taskfile/node_stdin.go index 387f50fe..b09a7795 100644 --- a/taskfile/node_stdin.go +++ b/taskfile/node_stdin.go @@ -12,12 +12,12 @@ import ( // A StdinNode is a node that reads a taskfile from the standard input stream. type StdinNode struct { - *BaseNode + *baseNode } func NewStdinNode(dir string) (*StdinNode, error) { return &StdinNode{ - BaseNode: NewBaseNode(dir), + baseNode: NewBaseNode(dir), }, nil }