mirror of
https://github.com/go-task/task.git
synced 2024-12-14 10:52:43 +02:00
22ce67c5e5
* feat: remote taskfiles over http * feat: allow insecure connections when --insecure flag is provided * feat: better error handling for fetch errors * fix: ensure cache directory always exists * fix: setup logger before everything else * feat: put remote taskfiles behind an experiment * feat: --download and --offline flags for remote taskfiles * feat: node.Read accepts a context * feat: experiment docs * chore: changelog * chore: remove unused optional param from Node interface * chore: tidy up and generalise NewNode function * fix: use sha256 in remote checksum * feat: --download by itself will not run a task * feat: custom error if remote taskfiles experiment is not enabled * refactor: BaseNode functional options and simplified FileNode * fix: use hex encoding for checksum instead of b64
55 lines
984 B
Go
55 lines
984 B
Go
package read
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/go-task/task/v3/internal/filepathext"
|
|
)
|
|
|
|
// A FileNode is a node that reads a taskfile from the local filesystem.
|
|
type FileNode struct {
|
|
*BaseNode
|
|
Dir string
|
|
Entrypoint string
|
|
}
|
|
|
|
func NewFileNode(uri string, opts ...NodeOption) (*FileNode, error) {
|
|
base := NewBaseNode(opts...)
|
|
if uri == "" {
|
|
d, err := os.Getwd()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
uri = d
|
|
}
|
|
path, err := existsWalk(uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &FileNode{
|
|
BaseNode: base,
|
|
Dir: filepath.Dir(path),
|
|
Entrypoint: filepath.Base(path),
|
|
}, nil
|
|
}
|
|
|
|
func (node *FileNode) Location() string {
|
|
return filepathext.SmartJoin(node.Dir, node.Entrypoint)
|
|
}
|
|
|
|
func (node *FileNode) Remote() bool {
|
|
return false
|
|
}
|
|
|
|
func (node *FileNode) Read(ctx context.Context) ([]byte, error) {
|
|
f, err := os.Open(node.Location())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
return io.ReadAll(f)
|
|
}
|