Example for std.lines(arr) function of Jsonnet

363 Views Asked by At

Can anyone help me with an example for std.lines(arr) function of Jsonnet? I am trying to create a bash script to clone multiple git repositories using values from an array. My array structure is given below.

gitRepo : [ { github_repo: "github.com/abcd.git", github_id: "tom", github_access_token: "1aae0a6dc19aef327565" }, { github_repo: "github.com/qwerty.git", github_id: "alice", github_access_token: "2e2eef327565" }, ], }

Thanks in advance...

1

There are 1 best solutions below

1
On

Found a solution for this from jsonnet google groups.

local config = [
  {
    github_repo: 'github.com/abcd.git',
    github_id: 'tom',
    github_access_token: '1aae0a6dc19aef327565',
  },
  {
    github_repo: 'github.com/qwerty.git',
    github_id: 'alice',
    github_access_token: '2e2eef327565',
  },
];
std.lines([
  'git clone %(github_repo)s --user=%(github_id)s --token=%(github_access_token)s' % item
  for item in config
])

test it with jsonnet -S test.jsonnet. (Note the Capital -S flag)

https://groups.google.com/forum/#!searchin/jsonnet/array%7Csort:date/jsonnet/SGADdQQ-vBs/Tig8DnsRBQAJ