kcmerrill / alfred

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

Cannot register variable using template #72

Closed iilyak closed 6 years ago

iilyak commented 6 years ago

I would like to register a variable which is a transformation of user's input. I can register ENV, but registering regular variable doesn't work as I would expect. The following works:

test1:
  summary: test
  prompt:
    foo: foo?
  env:
    FOO: echo {{ .Vars.foo | dir }}
  command:
    echo $FOO

it outputs the following

11:20 $ bin/alfred test1
[      0s] (13 Apr 18 11:20 PDT) test1 started [] test
[      0s] (13 Apr 18 11:20 PDT) test1 prompt foo?
bar/baz/foo
[      8s] (13 Apr 18 11:20 PDT) test1 registered foo bar/baz/foo
[      8s] (13 Apr 18 11:20 PDT) test1 set $FOO bar/baz
[      8s] (13 Apr 18 11:20 PDT)  bar/baz
[      8s] (13 Apr 18 11:20 PDT) test1 ✔ ok [] elapsed time '8s'

However following doesn't work

test2:
  summary: test2
  prompt:
    foo_raw: foo?
  register:
    foo: echo {{ .Vars.foo_raw | dir }}
  command:
    echo {{ .Vars.foo }}

outputs

bin/alfred test2
[      0s] (13 Apr 18 11:21 PDT) test2 template Invalid Argument(s)
kcmerrill commented 6 years ago

So the order in which these get run are determined by the manual. The reason this didn't work is because register was taking place before prompt.

I don't have a specific use case like the one you're regarding so all good here.