如何在 gcloud 命令中禁用更新通知?

yan*_*ana 3 google-compute-engine google-cloud-platform gcloud

我正在使用 Google Cloud SDK CLI(gcloud命令),命令很棒!虽然我想以 JSON 格式输出 Google Compute Engine 的实例列表(通过运行gcloud compute instances list --format json)并使用jq JSON 处理器对其进行过滤,但该命令有时会输出以下消息:

Updates are available for some Cloud SDK components.  To install
them, please run:
$ gcloud components update
Run Code Online (Sandbox Code Playgroud)

我知道消息很重要,但我想将 JSON 输出视为格式正确。有没有办法抑制消息?-q--verbosity none选项都不起作用。

小智 6

您可以使用以下命令禁用更新检查:

gcloud config set component_manager/disable_update_check true 
Run Code Online (Sandbox Code Playgroud)

但是,您的用例仍应使用更新消息。你真的看到了 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
    // ...
}
Run Code Online (Sandbox Code Playgroud)

这将允许您使用如下调用解析 JSON:

gcloud compute instances list --format=json | python -m json.tool # substitute your tool of choice here
Run Code Online (Sandbox Code Playgroud)