[英]Print hosting default URL (or channel URL) with Firebase CLI
The Firebase CLI tool can show me the default URLs of the hosting site(s) of a project in a human-readable format: Firebase CLI 工具可以以人类可读的格式向我显示项目托管站点的默认 URL:
$ firebase hosting:sites:list
Sites for project <my-app>
┌──────────────────┬──────────────────────────────────┬─────────────────┐
│ Site ID │ Default URL │ App ID (if set) │
├──────────────────┼──────────────────────────────────┼─────────────────┤
│ my-app │ https://<my-app>.web.app │ -- │
└──────────────────┴──────────────────────────────────┴─────────────────┘
If I have multiple channels, it can also show me the URLs for each channel on a given site:如果我有多个频道,它还可以显示给定站点上每个频道的 URL:
$ firebase hosting:channel:list
Channels for site <my-app>
┌────────────┬─────────────────────┬──────────────────────────────────┬─────────────┐
│ Channel ID │ Last Release Time │ URL │ Expire Time │
├────────────┼─────────────────────┼──────────────────────────────────┼─────────────┤
│ live │ 2022-10-27 15:06:54 │ https://<my-app>.web.app │ never │
└────────────┴─────────────────────┴──────────────────────────────────┴─────────────┘
But how do I print only the URL of a channel, for use in a shell script?但是我如何只打印一个频道的 URL,用于 shell 脚本? (Without resorting to regexes.) (不求助于正则表达式。)
There isn't any command that prints just the default URLs.没有任何命令只打印默认 URL。 The CLI uses a package cli-table
and prints all the data together. CLI 使用 package 客户cli-table
并将所有数据打印在一起。
You can however use the Firebase Hosting REST API to list all the sites of a project and their channels and create a script or even better fork the Firebase CLI and add a new function alongside listSites()
function of the CLI to print the URLs without the table.但是,您可以使用Firebase Hosting REST API列出项目的所有站点及其频道并创建脚本,或者甚至更好地分叉Firebase CLI并添加一个新的 function 旁边的listSites()
88340084806589桌子。
The REST APIs response is just an array of sites so it should be pretty straightforward: REST API 响应只是一组站点,因此应该非常简单:
{
"sites": [
{
"name": "projects/<project_id>/sites/<site_id>",
"defaultUrl": "https://<project_id>.web.app",
"type": "DEFAULT_SITE"
}
]
}
You can use --json
argument.您可以使用--json
参数。
Combine with jq, you can retrieve specific url.结合jq,可以检索出具体的url。
Example with live channel:直播频道示例:
$ firebase hosting:channel:list --json |\
jq '.result.channels[]|select(.name|contains("live")) | .url'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.