首页 > 解决方案 > Jsonnet 的 std.lines(arr) 函数示例

问题描述

谁能帮我举一个 Jsonnet 的 std.lines(arr) 函数的例子?我正在尝试创建一个 bash 脚本来使用数组中的值克隆多个 git 存储库。我的数组结构如下所示。

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" }, ], }

提前致谢...

标签: githububuntu-16.04jsonnet

解决方案


从 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
])

jsonnet -S test.jsonnet. (注意大写-S标志)

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


推荐阅读