kcmerrill / alfred

(v0.2) Even Batman needs a little help. Task runner. Automator. Build system.
MIT License
63 stars 14 forks source link

Masterminds/sprig functions are not working #50

Closed iilyak closed 6 years ago

iilyak commented 6 years ago

I am having the following tasks defined:

project:
  summary: Select project
  command: ls projects | bin/peco --prompt "project>"
  register: project
  tasks:
    edit

edit:
  summary: Open given file
  command: |
    echo {{ index .Vars "project" | trim }}

The error I am getting is

alfred project

[project] Select project (Args: [])
couchdb

---
✔ project DONE
panic: template: translate:1: function "trim" not defined

goroutine 1 [running]:
panic(0x3f4ae0, 0xc8200de570)
        /usr/local/go/src/runtime/panic.go:481 +0x3e6
text/template.Must(0x0, 0x79d028, 0xc8200de570, 0x0)
        /usr/local/go/src/text/template/helper.go:23 +0x4b
github.com/kcmerrill/alfred/alfred.(*Task).template(0xc8200c9680, 0xc820065200, 0x53, 0x496701, 0x0, 0x0)
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred/task.go:409 +0x251
github.com/kcmerrill/alfred/alfred.(*Task).Prepare(0xc8200c9680, 0xc82000a300, 0x0, 0x0, 0xc8200dc4e0, 0x0)
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred/task.go:361 +0x95f
github.com/kcmerrill/alfred/alfred.(*Alfred).runTask(0xc82005b180, 0xc8200de2c8, 0x4, 0xc82000a300, 0x0, 0x0, 0xc8200dce00, 0x1)
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred/alfred.go:157 +0x4d2
github.com/kcmerrill/alfred/alfred.(*Alfred).runTask(0xc82005b180, 0x7fff5fbff2af, 0x7, 0xc82000a300, 0x0, 0x0, 0x362c00, 0xc82000f7a0)
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred/alfred.go:300 +0x1a92
github.com/kcmerrill/alfred/alfred.(*Alfred).findTask(0xc82005b180, 0x3ec)
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred/alfred.go:106 +0x29f
github.com/kcmerrill/alfred/alfred.New(0xc82000a300, 0x2, 0x2)
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred/alfred.go:68 +0x2d7
main.main()
        /usr/src/app/build/src/github.com/kcmerrill/alfred/alfred.go:40 +0x8f2
iilyak commented 6 years ago

JFYI: I am trying to strip new line returned by peco

kcmerrill commented 6 years ago


[project] Select project (Args: [])
helloworld

---
✔ project DONE

[edit] Open given file (Args: [])
helloworld--noextraspaces

---
✔ edit DONE
04:26 PM ✔ kcmerrill  tmp ] cat alfred.yml
project:
  summary: Select project
  command: echo "helloworld   "
  register: project
  tasks:
    edit

edit:
  summary: Open given file
  command: |
    echo "{{ index .Vars "project" | trim }}--noextraspaces"```

---

Make sure youre on the latest and greatest.  If you are, that yaml for some reason that "|" is throwing me off. Try tossing quotes around that  ....

or try this:

```project:
  summary: Select project
  command: |
      ls projects | bin/peco --prompt "project>" # <-- make sure the spacing here is correct, github editor doesn't like me tabbing
  register: project
  tasks:
    edit

edit:
  summary: Open given file
  command: |
    echo {{ index .Vars "project" | trim }}```