T
Task•2y ago
sedyh

Supply non-constant arguments to dynamic variable

Hello I want to use charm/gum with task. I.e. I want to download binary if it not exist and use it with custom arguments. Something like this, but that piece is not valid config. What should I do?
version: "3"
silent: true
vars:
DIR: cache
GUM:
sh: go run github.com/charmbracelet/gum@latest {{.ARGS}}
tasks:
clean:
cmds:
- |
{{.GUM}} confirm "Clean?" && rm -rf {{.DIR}}
version: "3"
silent: true
vars:
DIR: cache
GUM:
sh: go run github.com/charmbracelet/gum@latest {{.ARGS}}
tasks:
clean:
cmds:
- |
{{.GUM}} confirm "Clean?" && rm -rf {{.DIR}}
10 Replies
vmaerten
vmaerten•2y ago
Hello ! Something like that should work :
version: "3"
silent: true
vars:
DIR: cache
GUM: go run github.com/charmbracelet/gum@latest
tasks:
clean:
cmds:
- '{{.GUM}} confirm "Clean?" && rm -rf {{.DIR}}'
version: "3"
silent: true
vars:
DIR: cache
GUM: go run github.com/charmbracelet/gum@latest
tasks:
clean:
cmds:
- '{{.GUM}} confirm "Clean?" && rm -rf {{.DIR}}'
vmaerten
vmaerten•2y ago
No description
sedyh
sedyhOP•2y ago
Oh, so all I was need is to make variable static...
vmaerten
vmaerten•2y ago
Yes 🙂 cmd in cmds are executed after being remplaced by the template engine
sedyh
sedyhOP•2y ago
Btw, can we also ignore error code printing from task? I know we had issue for reworking --silent flag, but maybe there are workarounds?
sedyh
sedyhOP•2y ago
No description
vmaerten
vmaerten•2y ago
You can use ignore_error: true For example:
version: "3"
silent: true
vars:
DIR: cache
GUM: go run github.com/charmbracelet/gum@latest
tasks:
clean:
ignore_error: true
cmds:
- '{{.GUM}} confirm "Clean?" && rm -rf {{.DIR}}'
version: "3"
silent: true
vars:
DIR: cache
GUM: go run github.com/charmbracelet/gum@latest
tasks:
clean:
ignore_error: true
cmds:
- '{{.GUM}} confirm "Clean?" && rm -rf {{.DIR}}'
No description
vmaerten
vmaerten•2y ago
The first one is with silent: true The second with silent: false
sedyh
sedyhOP•2y ago
But it will still print the exit status, right?
vmaerten
vmaerten•2y ago
Yes AFAIK, there is nothing to hide commands' output in Task You may need play with redirect stdout and stderr

Did you find this page helpful?