)
gogcli 使用指南gog sheets datasource table list列出 Connected Sheets 数据源表Extracts【免费下载链接】gogcliGoogle Workspace in your terminal.项目地址: https://gitcode.com/GitHub_Trending/gogcl/gogcligog sheets datasource table list是 gogcliGoogle Workspace in your terminal中用于**发现并列出 Google Sheets 中全部 Connected Sheets 数据源表即表格编辑器中的 extract 提取项**的只读命令。本文以该命令为线索完整讲解其命令语法、全部 Flags 参数、输出字段语义并结合源码与测试深入剖析其背后的spreadsheets.get锚点扫描与按数据源过滤机制帮助你准确掌握在终端里盘点一张电子表格挂接了哪些 BigQuery/Looker 数据提取的完整方法。命令概览语法、别名与层级table list位于命令层级gog sheets datasource table之下用于列出指定电子表格中的所有数据源表。由于该命令组在 Kong 中注册了多组别名实际输入时可以自由使用以下等价写法gog sheets datasource table list spreadsheetId [flags] # 等价写法别名展开后 gog sheets datasource tables list spreadsheetId gog sheets datasource extracts list spreadsheetId gog sheets connected-sheets table list spreadsheetId其完整 Usage 形态与gog schema --json生成文档一致为gog sheets (sheet) datasource (data-source,data-sources,connected-sheets) table (tables,extract,extracts) list spreadsheetId [flags]从源码看这一命令层级定义在 internal/cmd/sheets_datasource.go#L31-L35SheetsDataSourceTableCmd下挂载了list并标记为default:withargs即可省略子命令名直接携带参数调用、describe别名get,show,info与read别名values三个子命令而SheetsDataSourceListCmd的父节点SheetsDataSourceCmd则注册了datasource的别名data-source,data-sources,connected-sheets。也就是说gog sheets datasource list id、gog sheets datasource table list id与gog sheets connected-sheets table list id均指向同一套实现。必填参数spreadsheetId命令的唯一位置参数是电子表格 ID其解析逻辑位于 internal/cmd/sheets_datasource.go#L189-L227参数会先经过normalizeGoogleID与strings.TrimSpace处理兼容带前后空白的输入若最终为空命令立即返回usage(empty spreadsheetId)错误退出码为 2见 sheets_datasource_test.go#L241-L261 中TestSheetsDataSourceTableValidation对ExitCode的断言电子表格 ID 可以从 URL 中取得例如https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit中的1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms。专用过滤 Flag--data-source-id除全局 Flag 外该命令独有的参数是--data-source-id它用于只列出属于某个指定数据源Data Source的表。其定义为 internal/cmd/sheets_datasource.go#L46-L49type SheetsDataSourceTableListCmd struct { SpreadsheetID string arg: name:spreadsheetId help:Spreadsheet ID DataSourceID string name:data-source-id help:Only tables belonging to this data source ID }对应的过滤逻辑在Run中实现先取出全量表列表再按DataSourceID精确匹配保留条目因此多次出现相同数据源 ID 的表会全部返回# 列出某张电子表格中全部数据源表 gog --readonly --account youexample.com sheets datasource table list spreadsheetId # 只列出属于数据源 ds-table 的表 gog --readonly --account youexample.com sheets datasource table list spreadsheetId --data-source-id ds-table数据源 ID 的获取途径包括gog sheets datasource list spreadsheetId列出数据源摘要、gog sheets datasource describe spreadsheetId dataSourceId或在 Google Sheets 网页端的数据源侧边栏中查看。测试用例 sheets_datasource_test.go#L88-L99 演示了典型的组合用法sheets datasource table list connected1 --data-source-id ds-table --json并断言输出中包含anchor: Extracts!B3、rowLimit: 5、state: SUCCEEDED。输出解析表格式与 JSON 字段默认表格输出未指定输出格式时命令以表格形式输出列定义见 internal/cmd/sheets_datasource.go#L623-L633 的sheetsDataSourceTableColumns列头含义ANCHOR表的锚点单元格 A1 地址含工作表名如Extracts!B3DATA_SOURCE_ID该表所属数据源的 IDSELECTION列选择方式ColumnSelectionType如SELECTED/SYNC_ALLCOLUMNS表的列数从列名数组长度计算得出ROW_LIMIT表配置的行数上限0 表示不限制STATE最近一次执行状态SUCCEEDED/FAILED等LAST_REFRESH最近一次刷新时间ERROR执行出错时的错误码当电子表格中没有任何数据源表时命令在stderr打印No Connected Sheets>{ spreadsheetId: 1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms, tables: [ { anchor: Extracts!B3, sheetId: 101, sheetTitle: Extracts, dataSourceId: ds-table, columnSelectionType: SELECTED, columns: [word, word_count], rowLimit: 5, state: SUCCEEDED, lastRefreshTime: 2026-01-01T00:00:00Z } ] }各字段含义如下均由sheetsDataSourceTableToItem从 API 响应组装见 internal/cmd/sheets_datasource.go#L519-L540anchor锚点 A1 地址由工作表标题与行列号经sheetsa1.FormatCell计算得出是后续describe/read命令的寻址依据sheetId/sheetTitle锚点所在工作表的数字 ID 与标题dataSourceId所属数据源 IDcolumnSelectionTypeSELECTED仅表内选定的列或SYNC_ALL同步数据源的全部列columns列名数组SYNC_ALL类型表通常为空数组其列定义保存在关联的DATA_SOURCE工作表上见下文原理部分rowLimit行数上限0表示不限制state/lastRefreshTime/errorCode/errorMessage来自 Google API 的DataExecutionStatus通过setSheetsDataExecutionStatus拷贝到条目上。底层原理如何从一张电子表格中发现所有表数据源表在 Sheets API 中没有独立的 ID它的全部定义只存在于表格左上角锚点单元格的dataSourceTable属性中docs/sheets-connected.md 的 Discover and read extracts 一节对此有明确说明。因此table list的发现逻辑必须扫描整张表调用spreadsheets.get并携带IncludeGridData(true)与受限字段掩码internal/cmd/sheets_datasource.go#L389-L398spreadsheetId,sheets(properties(sheetId,title,index,sheetType,gridProperties(rowCount,columnCount),dataSourceSheetProperties),data(startRow,startColumn,rowData(values(dataSourceTable))))这个字段掩码刻意只请求锚点定义与相关工作表元数据避免拉取整张表的单元格数据从而控制请求成本测试 sheets_datasource_test.go#L134-L137 也专门断言了查询串中必须出现includeGridDatatrue与dataSourceTable。collectSheetsDataSourceTablesinternal/cmd/sheets_datasource.go#L479-L517遍历每个 sheet 的每个 grid、每行、每列凡是单元格携带DataSourceTable字段的就按grid.StartRow/StartColumn与行内偏移换算出行列号1 起始构造一个表条目最终结果按SheetID → 行号 → 列号排序保证输出顺序稳定可预期。这也解释了为什么输出中一定有anchor列锚点是数据源表在 Google Sheets 中的唯一寻址方式后续的gog sheets datasource table describe spreadsheetId sheet!A1与read命令都依赖它来定位表describe/read会先调用validateSheetsDataSourceTableArgs强制校验锚点必须是含工作表名的单个单元格例如Extracts!B3。前置条件授权与 BigQuery 只读 Scope读取包含 BigQuery Connected Sheets 数据的响应时Google 要求同时具备 Sheets API 授权与https://www.googleapis.com/auth/bigquery.readonly作用域。gogcli 的普通sheets授权有意不请求BigQuery scope相关常量定义在 internal/cmd/sheets_datasource.go#L19const connectedSheetsBigQueryScope https://www.googleapis.com/auth/bigquery.readonly若账户尚未同时具备这两项授权需要重新授权并强制进入同意页完整说明见 docs/sheets-connected.md 的 Authorize BigQuery access explicitly 一节gog auth add youexample.com \ --services sheets \ --extra-scopes https://www.googleapis.com/auth/bigquery.readonly \ --force-consent如果账户 token 覆盖的服务更多应保留原有的--services选择包括更窄的--drive-scope或--gmail-scope而不是收窄为sheets。当table list因 scope 不足失败时命令会通过wrapConnectedSheetsReadErrorinternal/cmd/sheets_datasource.go#L589-L609识别insufficient authentication scopes之类的错误并直接输出一条包含上述--extra-scopes的重新授权提示对应的单元测试TestWrapConnectedSheetsReadErrorsheets_datasource_test.go#L263-L273验证了这一提示逻辑同时确认普通的permission denied错误不会被误包装。Looker 数据源复用账户已有的 Looker 关联但命令形态与输出结构完全一致。输出控制与脚本化实践table list是只读命令非常适合在 CI 或 Agent 工作流中做盘点。推荐组合# 1) JSON 输出供 jq 等工具做结构化处理 gog --readonly --no-input --account youexample.com \ sheets datasource table list spreadsheetId --json # 2) 只看锚点与所属数据源配合 --select 只取需要的字段 gog --readonly --account youexample.com \ sheets datasource table list spreadsheetId --json --select tables.anchor,tables.dataSourceId # 3) TSV 稳定文本输出便于 grep / awk 管道处理无颜色、无表格框线 gog --readonly --account youexample.com \ sheets datasource table list spreadsheetId --plain若在循环中对多个电子表格连续调用建议加入适当间隔——Back-to-back 读取可能触及 Sheets API 每分钟配额docs/sheets-connected.md 在read一节同样给出了这一提示。全局 Flags 完整参考gog sheets datasource table list继承了 gogcli 的所有全局 Flags与gog schema --json生成文档一致。下表为完整列表Flag类型默认值说明--access-tokenstring直接使用提供的访问令牌绕过存储的刷新令牌令牌约 1 小时后过期-a--account--acctstring账户邮箱、别名或auto用于已认证的 Google API 命令--clientstringOAuth 客户端名称选择已存储的凭据与令牌桶--colorstringauto颜色输出auto|always|never--data-source-idstring只列出属于该数据源 ID 的表本命令独有--disable-commandsstring逗号分隔的禁用命令列表支持点路径-n--dry-run--dryrun--noop--previewbool不执行修改打印预期动作并以成功退出--enable-commandsstring逗号分隔的启用命令前缀列表支持点路径限制 CLI--enable-commands-exactstring逗号分隔的精确启用命令列表支持点路径父命令不会启用子命令-y--force--assume-yes--yesbool对破坏性命令跳过确认--gmail-no-sendboolfalse阻止 Gmail 发送操作Agent 安全-h--helpkong.helpFlag显示上下文相关的帮助--homestring覆盖 gogcli 的 config/data/state/cache 根目录等价于GOG_HOME-j--json--machineboolfalse向 stdout 输出 JSON最适合脚本化--no-input--non-interactive--noninteractivebool绝不交互提示失败即退出适合 CI-p--plain--tsvboolfalse向 stdout 输出稳定的可解析文本TSV无颜色--quota-projectstring计费 Google Cloud 项目作为X-Goog-User-Project发送部分 API 在--access-token或 ADC 下要求--readonlyboolfalse运行时阻止变更型 API 请求auth add也会请求只读 OAuth scope--results-onlyboolJSON 模式下仅输出主要结果丢弃nextPageToken等信封字段--select--pick--projectstringJSON 模式下选择逗号分隔的字段尽力而为支持点路径。多数命令优先使用--fields-v--verbosebool开启详细日志--versionkong.VersionFlag打印版本并退出--wrap-untrustedboolfalseJSON/raw 输出中为获取的外部文本字段包裹不受信任内容标记与兄弟命令的配合从发现到读取table list只是数据源表工作流的入口它与同级命令构成完整的发现-描述-读取链路子命令定义见 internal/cmd/sheets_datasource.go#L31-L35# 1) 发现列出所有表取得 anchor 与 dataSourceId gog --readonly --account youexample.com sheets datasource table list spreadsheetId --json # 2) 描述查看某张表的完整定义列名、行数上限、执行状态 gog --readonly --account youexample.com sheets datasource table describe spreadsheetId Extracts!B3 --json # 3) 读取按表自身的行数上限有界读取数据默认最多 1000 行数据 表头 gog --readonly --account youexample.com sheets datasource table read spreadsheetId Extracts!B3 --max-rows 250 --json一个典型的自动化场景是先用table list --json批量盘点锚点再对每个锚点执行read拉取数据并用--render FORMULA或--render UNFORMATTED_VALUE覆盖默认的FORMATTED_VALUE渲染方式docs/sheets-connected.md 对此有完整说明。由于list已把rowLimit、state、errorCode等执行状态一并带出还可以用它作为哪些表最近刷新失败的巡检手段。进一步阅读gog sheets datasource table 命令总览包含describe/read子命令与全部 Flagsgog sheets datasource 数据源管理命令add/update/refresh/delete/list/describeConnected Sheets 完整指南授权 BigQuery scope、增删改查数据源的端到端用法命令索引全部命令文档的入口命令实现源码table list的Run、锚点扫描与字段组装逻辑命令测试用例TestSheetsDataSourceTableListDescribeAndRead等验证锚点、过滤与字段掩码行为【免费下载链接】gogcliGoogle Workspace in your terminal.项目地址: https://gitcode.com/GitHub_Trending/gogcl/gogcli创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考