Skip to content

Read file contents and do string replacement on that #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
garo opened this issue Sep 22, 2016 · 2 comments
Closed

Read file contents and do string replacement on that #238

garo opened this issue Sep 22, 2016 · 2 comments

Comments

@garo
Copy link

garo commented Sep 22, 2016

I have an use case with Terraform that I would want to read a file from system, do a set of string replacements in that file based in variables defined in jsonnet and then base64 encode the resulted string so that I can pass that into the created json.

I suppose that I could do a pull request for a function which loads a file from the filesystem as a string, if it's generally agreed that it's a feature suitable to the stdlib.

@mikedanese
Copy link
Contributor

mikedanese commented Sep 22, 2016

Can you use 'importstr'?

std.assertEqual(importstr "lib/some_file.txt", "Hello World!\n") &&

@sparkprime
Copy link
Collaborator

Use importstr and then do python-style string formatting, e.g.
(importstr "myfile.txt") % { foo: "bar" } and inside the file, do

I spend most of my time at the %(foo)s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants