2023-12-29 22:32:03 +02:00
package taskfile
2023-09-02 22:24:01 +02:00
import (
2023-09-12 23:42:54 +02:00
"context"
2023-09-02 22:24:01 +02:00
"strings"
2023-09-12 23:42:54 +02:00
"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/experiments"
2023-09-02 22:24:01 +02:00
)
type Node interface {
2023-09-12 23:42:54 +02:00
Read ( ctx context . Context ) ( [ ] byte , error )
2023-09-02 22:24:01 +02:00
Parent ( ) Node
Location ( ) string
2023-09-12 23:42:54 +02:00
Optional ( ) bool
Remote ( ) bool
2023-09-02 22:24:01 +02:00
}
2023-09-12 23:42:54 +02:00
func NewNode (
uri string ,
insecure bool ,
opts ... NodeOption ,
) ( Node , error ) {
var node Node
var err error
switch getScheme ( uri ) {
case "http" , "https" :
node , err = NewHTTPNode ( uri , insecure , opts ... )
2023-09-02 22:24:01 +02:00
default :
2023-09-12 23:42:54 +02:00
// If no other scheme matches, we assume it's a file
node , err = NewFileNode ( uri , opts ... )
}
if node . Remote ( ) && ! experiments . RemoteTaskfiles {
2023-12-29 22:42:30 +02:00
return nil , errors . New ( "task: Remote taskfiles are not enabled. You can read more about this experiment and how to enable it at https://taskfile.dev/experiments/remote-taskfiles" )
2023-09-02 22:24:01 +02:00
}
2023-09-12 23:42:54 +02:00
return node , err
2023-09-02 22:24:01 +02:00
}
func getScheme ( uri string ) string {
if i := strings . Index ( uri , "://" ) ; i != - 1 {
return uri [ : i ]
}
return ""
}