Comments (8)
It would be nice to have a PR for it if you have time. 👍
If you don't, I'll do with time.
from task.
What exactly do you expect? Do you have an example Taskfile and expected output?
Task disallows that because it breaks sh commands:
do-something -o output {{.INPUT}} # multiline
do-something -o output file1
file2
file3
I just tried and Makefiles replaces line breaks with " "
:
FOO := $(shell echo "foo\nbar")
echo:
# echoes "foo bar"
@echo $(FOO)
.PHONY: echo
My proposal would be convert multiline vars to []string
, so one could either join or loop.
build:
cmds:
- minify -o bundle.js {{join .JS_FILES " "}}
or
build:
cmds:
- |
{{range $file := .JS_FILES}}
minify -o "dist/{{$file}}" "src/{{$file}}"
{{end}}
from task.
If you quote it, it doesn't break the shell cmd.
default:
vars:
RSA_KEY:
sh: pass mysecret # where pass is a Unix keychain tool, and the stored secret is multi-line.
cmds:
- ./myprogram -private-key='{{.RSA_KEY}}'
Today we do the same using set
, but the way set
works by setting this env globally for every other task with a potential of data-races is not great. Which I assume is part of the reason for it being deprecated?
I don't like the idea of making it a string slice. That's not what you expect to get as a user.
If you want to avoid users making mistakes, it could be a deliberate flag:
default:
vars:
RSA_KEY:
sh: pass mysecret
multiline: true # skip multi-line check and don't trim trailing new-lines.
It's probably not super intuitive for new users as you would only need to use this flag if you set a var from sh, not when using another (already multiline) variable, or explicetly declare it multiline in a var via yaml. However it's probably good enough, especially if you get a hint about the flag on errors. It certainly would be for us.
from task.
@smyrman I agree it's a bit unintuitive to the user, but we could have a default String()
function that just joins it with a space (or maybe a line break). See https://play.golang.org/p/0vjZypJwRe
So most users would not need to bother about it, but could also join with a different value if they want. What do you think about it?
And yes, I want to deprecated set
ASAP. I think other than multiline, everything is already possible via task parameters. (Am I missing something?).
from task.
a default String()
That might just work:-)
from task.
Do you want me to do a PR, or will you?
I would like to at least test it to see how it works for our use-case.
from task.
As a heads-up, when it came to implementation, it still seams better to handle this at command parse time. Replacing the Var.Static
attribute with a []string
is a bigger and also a breaking change. E.g. it would break both set
and cases where the end-users define multiline values in task via yaml
:
default:
vars:
MLINE: |
foo
bar
baz
cmds:
- echo "{{.MLINE}}"
Instead I am doing the following for the first PR at least (README extract):
Dynamic variables
(...)
By default, the result of the shell command is concatenated to one line, and all
trailing and leading white-space are trimmed. This makes the variable somewhat
safer to use in shell commands, and should work well in most use cases.
For advanced use cases, you may set the multiline
and/or notrim
flags. By
doing this, you must ensure quoting is used in a safe manner when you use the
variable to not break the shell command into two or more commands. The same is
true for multi-line values supplied via yaml.
build:
cmds:
- go build -ldflags='-X main.History="{{.GIT_HISTORY | replace "'" "\'"| replace """ "\""}}"' main.go
vars:
GIT_COMMIT:
sh: git log -n 5
multiline: true
notrim: true
END README
The code for this is clean enough, I will push it in a while...
from task.
btw, the other use-cases you mentioned @andreynering, could be handled by template functions:
build:
cmds:
- |
{{range $file := splitList "\n" .JS_FILES }}
minify -o "dist/{{$file}}" "src/{{$file}}"
{{end}}
from task.
Related Issues (20)
- Taskfile doesn't expand env vars in global variable section
- Map variables experiment HOT 5
- Cannot override global variables in included Taskfiles since 3.36.0 HOT 7
- can't disable color in taskfile.yml
- ( is not a valid word HOT 1
- Implement support for the GNU Make jobserver
- Watcher not working in a docker container if user is not root
- Regression: Piping to "task" command results in `task: Missing schema version in Taskfile "__stdin__"` HOT 9
- Can environment variables support reference variables like variables? Refer to env in k8s
- Provide some typical cases of practical applications as reference for configuration or various usages HOT 2
- Unable to override dotenv file loaded using $ENV value, as per the example in the docs HOT 1
- When calling a subtask, the passed variable cannot directly overwrite the value in the subtask, which is inconsistent with the document description. HOT 1
- for loop does not take effect in deps HOT 1
- The for loop does not support specifying multiple commands HOT 1
- Template-related errors are difficult to understand
- Add `q` alias for `shellQuote` template function? HOT 2
- Exclude doesn't support globbing HOT 1
- Variables are initialized at start of taskfile and not when I actually need them to be initialized
- fatal error: concurrent map writes HOT 3
- Cannot include multiple time the same Taskfile with differents namespaces HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from task.