![如何在 gcloud 命令中禁用更新通知?](https://linux22.com/image/663464/%E5%A6%82%E4%BD%95%E5%9C%A8%20gcloud%20%E5%91%BD%E4%BB%A4%E4%B8%AD%E7%A6%81%E7%94%A8%E6%9B%B4%E6%96%B0%E9%80%9A%E7%9F%A5%EF%BC%9F.png)
我正在使用 Google Cloud SDK CLI(gcloud
命令),这个命令很棒!虽然我想以 JSON 格式输出 Google Compute Engine 的实例列表(通过运行gcloud compute instances list --format json
)并使用进行过滤杰奇JSON 处理器,该命令有时会输出以下消息:
Updates are available for some Cloud SDK components. To install
them, please run:
$ gcloud components update
我知道消息很重要,但我想将 JSON 输出视为格式正确的。有没有办法隐藏该消息?-q
和--verbosity none
选项均无效。
答案1
您可以使用以下命令禁用更新检查:
gcloud config set component_manager/disable_update_check true
但是,您的用例仍应适用于更新消息。您真的看到 JSON 解析器存在问题吗?预期的行为是 JSON 输出转到标准输出,而更新消息转到标准错误。
$ gcloud compute instances list --format=json > stdout.log 2> stderr.log
$ cat stderr.log
Updates are available for some Cloud SDK components. To install them, please run:
$ gcloud components update
$ cat stdout.log
{
// JSON here
// ...
}
这将允许您使用如下调用来解析 JSON:
gcloud compute instances list --format=json | python -m json.tool # substitute your tool of choice here