mirror of
https://github.com/go-task/task.git
synced 2026-05-18 05:05:20 +02:00
feat(templater): add absPath template function (#2788)
Signed-off-by: Mateen Anjum <mateenali66@gmail.com> Co-authored-by: Valentin Maerten <maerten.valentin@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@ func init() {
|
||||
"IsSH": IsSH, // Deprecated
|
||||
"joinPath": filepath.Join,
|
||||
"relPath": filepath.Rel,
|
||||
"absPath": filepath.Abs,
|
||||
"merge": merge,
|
||||
"spew": spew.Sdump,
|
||||
"fromYaml": fromYaml,
|
||||
|
||||
21
task_test.go
21
task_test.go
@@ -2601,6 +2601,27 @@ func TestSplitArgs(t *testing.T) {
|
||||
assert.Equal(t, "3\n", buff.String())
|
||||
}
|
||||
|
||||
func TestAbsPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.NewExecutor(
|
||||
task.WithDir("testdata/abs_path"),
|
||||
task.WithStdout(&buff),
|
||||
task.WithStderr(&buff),
|
||||
task.WithSilent(true),
|
||||
)
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
err := e.Run(t.Context(), &task.Call{Task: "default"})
|
||||
require.NoError(t, err)
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
expected := filepath.Join(cwd, "bar") + "\n"
|
||||
assert.Equal(t, expected, buff.String())
|
||||
}
|
||||
|
||||
func TestSingleCmdDep(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
6
testdata/abs_path/Taskfile.yml
vendored
Normal file
6
testdata/abs_path/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- cmd: echo '{{absPath "foo/../bar"}}'
|
||||
@@ -617,6 +617,7 @@ tasks:
|
||||
- echo "{{.WIN_PATH | fromSlash}}" # Convert to OS-specific slashes
|
||||
- echo "{{joinPath .OUTPUT_DIR .BINARY_NAME}}" # Join path elements
|
||||
- echo "Relative {{relPath .ROOT_DIR .TASKFILE_DIR}}" # Get relative path
|
||||
- echo '{{absPath "../sibling"}}' # Resolve to an absolute path
|
||||
```
|
||||
|
||||
### Data Structure Functions
|
||||
|
||||
Reference in New Issue
Block a user