Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions shortcuts/apps/apps_db_audit_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{Name: "until", Desc: "filter: event at or before; same formats as --since"},
{Name: "page-size", Type: "int", Default: "20", Desc: "page size"},
{Name: "page-token", Desc: "pagination cursor from previous response"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Comment thread
chenxingyang1019 marked this conversation as resolved.
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -145,7 +145,10 @@
existing := map[string]bool{}
token := ""
for {
params := map[string]interface{}{"env": env, "page_size": 100}
params := map[string]interface{}{"page_size": 100}
if env != "" {
params["env"] = env

Check warning on line 150 in shortcuts/apps/apps_db_audit_list.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/apps/apps_db_audit_list.go#L150

Added line #L150 was not covered by tests
}
if token != "" {
params["page_token"] = token
}
Expand All @@ -168,7 +171,11 @@

// fetchAuditEnabledTables 拉审计状态,返回当前已开启审计的表名集合(status 命令同源接口)。
func fetchAuditEnabledTables(rctx *common.RuntimeContext, appID, env string) (map[string]bool, error) {
data, err := rctx.CallAPITyped("GET", appAuditStatusPath(appID), map[string]interface{}{"env": env}, nil)
statusParams := map[string]interface{}{}
if env != "" {
statusParams["env"] = env

Check warning on line 176 in shortcuts/apps/apps_db_audit_list.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/apps/apps_db_audit_list.go#L176

Added line #L176 was not covered by tests
}
data, err := rctx.CallAPITyped("GET", appAuditStatusPath(appID), statusParams, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -208,11 +215,10 @@

// buildAuditListParams 组装 audit_list 查询参数:env / tables(逗号拼接) / page_size 及可选 since/until/page_token。
func buildAuditListParams(rctx *common.RuntimeContext, tables []string) map[string]interface{} {
params := map[string]interface{}{
"env": dbEnv(rctx),
params := dbEnvParams(rctx, map[string]interface{}{
"tables": strings.Join(tables, ","),
"page_size": rctx.Int("page-size"),
}
})
addStr := func(flag, key string) {
if v := strings.TrimSpace(rctx.Str(flag)); v != "" {
params[key] = v
Expand Down
12 changes: 6 additions & 6 deletions shortcuts/apps/apps_db_audit_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var AppsDBAuditEnable = common.Shortcut{
{Name: "app-id", Desc: "Miaoda app id", Required: true},
{Name: "table", Desc: "table to enable audit for", Required: true},
{Name: "retention", Default: "7d", Enum: auditRetentions, Desc: "how long to keep audit logs"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand All @@ -47,7 +47,7 @@ var AppsDBAuditEnable = common.Shortcut{
return common.NewDryRunAPI().
POST(appAuditSetPath(appID)).
Desc("Enable table audit").
Params(map[string]interface{}{"env": dbEnv(rctx)}).
Params(dbEnvParams(rctx, map[string]interface{}{})).
Body(map[string]interface{}{"table": strings.TrimSpace(rctx.Str("table")), "enabled": true, "retention": rctx.Str("retention")})
},
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
Expand All @@ -60,7 +60,7 @@ var AppsDBAuditEnable = common.Shortcut{
stop := rctx.StartSpinner("Enabling audit logging for " + table)
defer stop()
data, err := rctx.CallAPITyped("POST", appAuditSetPath(appID),
map[string]interface{}{"env": dbEnv(rctx)},
dbEnvParams(rctx, map[string]interface{}{}),
map[string]interface{}{"table": table, "enabled": true, "retention": retention})
stop()
if err != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ var AppsDBAuditDisable = common.Shortcut{
Flags: append([]common.Flag{
{Name: "app-id", Desc: "Miaoda app id", Required: true},
{Name: "table", Desc: "table to disable audit for", Required: true},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand All @@ -108,7 +108,7 @@ var AppsDBAuditDisable = common.Shortcut{
return common.NewDryRunAPI().
POST(appAuditSetPath(appID)).
Desc("Disable table audit").
Params(map[string]interface{}{"env": dbEnv(rctx)}).
Params(dbEnvParams(rctx, map[string]interface{}{})).
Body(map[string]interface{}{"table": strings.TrimSpace(rctx.Str("table")), "enabled": false})
},
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
Expand All @@ -118,7 +118,7 @@ var AppsDBAuditDisable = common.Shortcut{
}
table := strings.TrimSpace(rctx.Str("table"))
data, err := rctx.CallAPITyped("POST", appAuditSetPath(appID),
map[string]interface{}{"env": dbEnv(rctx)},
dbEnvParams(rctx, map[string]interface{}{}),
map[string]interface{}{"table": table, "enabled": false})
if err != nil {
return withAppsHint(err, dbAuditSetHint)
Expand Down
4 changes: 2 additions & 2 deletions shortcuts/apps/apps_db_audit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var AppsDBAuditStatus = common.Shortcut{
Flags: append([]common.Flag{
{Name: "app-id", Desc: "Miaoda app id", Required: true},
{Name: "table", Desc: "show status for a single table (default: all configured tables)"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -75,7 +75,7 @@ var AppsDBAuditStatus = common.Shortcut{

// buildAuditStatusParams 组装 audit_status 查询参数:env 及可选 table(单表查询)。
func buildAuditStatusParams(rctx *common.RuntimeContext) map[string]interface{} {
params := map[string]interface{}{"env": dbEnv(rctx)}
params := dbEnvParams(rctx, map[string]interface{}{})
if t := strings.TrimSpace(rctx.Str("table")); t != "" {
params["table"] = t
}
Expand Down
7 changes: 3 additions & 4 deletions shortcuts/apps/apps_db_changelog_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var AppsDBChangelogList = common.Shortcut{
{Name: "until", Desc: "filter: changed at or before; same formats as --since"},
{Name: "page-size", Type: "int", Default: "20", Desc: "page size"},
{Name: "page-token", Desc: "pagination cursor from previous response"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -77,10 +77,9 @@ var AppsDBChangelogList = common.Shortcut{

// buildChangelogParams 组装 changelog_list 查询参数:env / page_size 及可选 table/change_id/since/until/page_token。
func buildChangelogParams(rctx *common.RuntimeContext) map[string]interface{} {
params := map[string]interface{}{
"env": dbEnv(rctx),
params := dbEnvParams(rctx, map[string]interface{}{
"page_size": rctx.Int("page-size"),
}
})
addStr := func(flag, key string) {
if v := strings.TrimSpace(rctx.Str(flag)); v != "" {
params[key] = v
Expand Down
34 changes: 20 additions & 14 deletions shortcuts/apps/apps_db_data_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{Name: "table", Desc: "source table", Required: true},
{Name: "output", Desc: "local output path; extension picks format .csv/.json/.sql (default: <table>.csv)"},
{Name: "limit", Type: "int", Default: "5000", Desc: "max rows to export (1..5000)"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "source db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "source db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -75,10 +75,10 @@
return common.NewDryRunAPI().
GET(appDataExportPath(appID)).
Desc("Export Miaoda app table data (raw bytes)").
Params(map[string]interface{}{
"env": dbEnv(rctx), "table": strings.TrimSpace(rctx.Str("table")),
Params(dbEnvParams(rctx, map[string]interface{}{
"table": strings.TrimSpace(rctx.Str("table")),
"format": format, "limit": rctx.Int("limit"),
})
}))
},
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
appID, err := requireAppID(rctx.Str("app-id"))
Expand All @@ -95,15 +95,18 @@
// total 查询失败不阻断导出——回退到按导出文件内容数行。
total, totalErr := queryExportTotal(rctx, appID, dbEnv(rctx), table)

exportQuery := larkcore.QueryParams{
"table": []string{table},
"format": []string{format},
"limit": []string{strconv.Itoa(rctx.Int("limit"))},
}
if env := dbEnv(rctx); env != "" {
exportQuery["env"] = []string{env}

Check warning on line 104 in shortcuts/apps/apps_db_data_export.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/apps/apps_db_data_export.go#L104

Added line #L104 was not covered by tests
}
resp, err := rctx.DoAPI(&larkcore.ApiReq{
HttpMethod: http.MethodGet,
ApiPath: appDataExportPath(appID),
QueryParams: larkcore.QueryParams{
"env": []string{dbEnv(rctx)},
"table": []string{table},
"format": []string{format},
"limit": []string{strconv.Itoa(rctx.Int("limit"))},
},
HttpMethod: http.MethodGet,
ApiPath: appDataExportPath(appID),
QueryParams: exportQuery,
})
if err != nil {
return withAppsHint(errs.NewNetworkError(errs.SubtypeNetworkTransport, "export request failed").WithCause(err).WithRetryable(), dbDataExportHint)
Expand Down Expand Up @@ -157,8 +160,11 @@
// queryExportTotal 调 GetAppTableRecordList(page_size=1)取 total(符合条件的记录总数)。
// 该接口与 +db-data-export 同为 spark:app:read scope,避免导出命令被迫升级到写权限。
func queryExportTotal(rctx *common.RuntimeContext, appID, env, table string) (int, error) {
raw, err := rctx.CallAPITyped("GET", appTableRecordsPath(appID, table),
map[string]interface{}{"env": env, "page_size": 1}, nil)
params := map[string]interface{}{"page_size": 1}
if env != "" {
params["env"] = env

Check warning on line 165 in shortcuts/apps/apps_db_data_export.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/apps/apps_db_data_export.go#L165

Added line #L165 was not covered by tests
}
raw, err := rctx.CallAPITyped("GET", appTableRecordsPath(appID, table), params, nil)
if err != nil {
return 0, err
}
Expand Down
10 changes: 7 additions & 3 deletions shortcuts/apps/apps_db_data_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{Name: "app-id", Desc: "Miaoda app id", Required: true},
{Name: "file", Desc: "local data file (.csv/.json), relative to cwd", Required: true},
{Name: "table", Desc: "target table (default: file name without extension)"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -76,7 +76,7 @@
return common.NewDryRunAPI().
POST(appDataImportPath(appID)).
Desc("Import data file into Miaoda app table (multipart upload)").
Params(map[string]interface{}{"env": dbEnv(rctx), "table": importTableName(rctx)}).
Params(dbEnvParams(rctx, map[string]interface{}{"table": importTableName(rctx)})).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C3 'env|environment' shortcuts/apps/apps_db_data_import_test.go

Repository: larksuite/cli

Length of output: 2062


🏁 Script executed:

#!/bin/bash
sed -n '1,260p' shortcuts/apps/apps_db_data_import_test.go

Repository: larksuite/cli

Length of output: 6382


Add an assertion for the default env in the omitted---environment dry-run case. TestAppsDBDataImport_TableDefaultsToFileBasename only checks the derived table name; it should also cover the new unset-env default so the dry-run request shape doesn’t regress.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/apps/apps_db_data_import.go` at line 79, The dry-run test for the
omitted --environment path only verifies the derived table name and should also
assert the default env behavior. Update
TestAppsDBDataImport_TableDefaultsToFileBasename to check the request shape
produced by dbEnvParams and Params, specifically that env is unset/defaulted in
the dry-run case when no environment is provided, so the default handling stays
covered.

Source: Coding guidelines

Body(map[string]interface{}{"file_name": fileName, "file": "<contents of --file>"})
},
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
Expand All @@ -100,10 +100,14 @@
fd.AddField("file_name", fileName)
fd.AddFile("file", bytes.NewReader(content))

importQuery := larkcore.QueryParams{"table": []string{table}}
if env := dbEnv(rctx); env != "" {
importQuery["env"] = []string{env}

Check warning on line 105 in shortcuts/apps/apps_db_data_import.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/apps/apps_db_data_import.go#L105

Added line #L105 was not covered by tests
}
resp, err := rctx.DoAPI(&larkcore.ApiReq{
HttpMethod: http.MethodPost,
ApiPath: appDataImportPath(appID),
QueryParams: larkcore.QueryParams{"env": []string{dbEnv(rctx)}, "table": []string{table}},
QueryParams: importQuery,
Body: fd,
}, larkcore.WithFileUpload())
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions shortcuts/apps/apps_db_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var AppsDBExecute = common.Shortcut{
{Name: "sql", Desc: "SQL text; use - to read stdin. Mutually exclusive with --file",
Input: []string{common.Stdin}},
{Name: "file", Desc: "path to a .sql file (relative to cwd). Mutually exclusive with --sql"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -291,10 +291,9 @@ func parseErrorSentinel(data string) (int, string) {
//
// CLI 永远走 DBA 模式,原子性由用户在 SQL 内显式 BEGIN/COMMIT 控制;不暴露 transactional flag 给用户。
func buildDBSQLParams(rctx *common.RuntimeContext) map[string]interface{} {
return map[string]interface{}{
"env": dbEnv(rctx),
return dbEnvParams(rctx, map[string]interface{}{
"transactional": false,
}
})
}

// resolveExecuteSQL 返回要执行的 SQL,在用时(DryRun/Execute)现读,使 --file 的内容
Expand Down
6 changes: 3 additions & 3 deletions shortcuts/apps/apps_db_quota_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
HasFormat: true,
Flags: append([]common.Flag{
{Name: "app-id", Desc: "Miaoda app id", Required: true},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand All @@ -41,14 +41,14 @@
return common.NewDryRunAPI().
GET(appDbQuotaPath(appID)).
Desc("Get Miaoda app database storage usage").
Params(map[string]interface{}{"env": dbEnv(rctx)})
Params(dbEnvParams(rctx, map[string]interface{}{}))

Check warning on line 44 in shortcuts/apps/apps_db_quota_get.go

View check run for this annotation

Codecov / codecov/patch

shortcuts/apps/apps_db_quota_get.go#L44

Added line #L44 was not covered by tests
},
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
appID, err := requireAppID(rctx.Str("app-id"))
if err != nil {
return err
}
data, err := rctx.CallAPITyped("GET", appDbQuotaPath(appID), map[string]interface{}{"env": dbEnv(rctx)}, nil)
data, err := rctx.CallAPITyped("GET", appDbQuotaPath(appID), dbEnvParams(rctx, map[string]interface{}{}), nil)
Comment on lines +44 to +51

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd -a 'apps_db_quota_get.*test.*\.go'
rg -n -C3 'env|environment' shortcuts/apps/apps_db_quota_get_test.go 2>/dev/null

Repository: larksuite/cli

Length of output: 151


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Files matching apps_db_quota_get test patterns:\n'
fd -a 'apps_db_quota_get' shortcuts 2>/dev/null || true
printf '\nAll tests under shortcuts/apps related to db quota:\n'
fd -a 'db_quota' shortcuts/apps 2>/dev/null || true
printf '\nDirect listing of relevant files:\n'
git ls-files 'shortcuts/apps/*quota*' 'shortcuts/apps/*dryrun*' 'shortcuts/apps/*db*test*.go'

Repository: larksuite/cli

Length of output: 930


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the exact file and nearby tests, then inspect just the relevant slices.
git ls-files 'shortcuts/apps/*.go' | rg 'apps_db_(quota|get|execute|table_list).*test|apps_db_quota_get\.go|apps_db_execute_dryrun_test\.go|apps_db_table_list_dryrun_test\.go'

Repository: larksuite/cli

Length of output: 268


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
root = Path('.')
matches = []
for p in root.rglob('*.go'):
    s = p.as_posix()
    if 'shortcuts/apps/' in s and ('quota' in s or 'dryrun' in s or 'table_list' in s or 'execute' in s):
        matches.append(s)
for s in sorted(matches):
    print(s)
PY

Repository: larksuite/cli

Length of output: 470


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'apps_db_quota_get.go outline:\n'
ast-grep outline shortcuts/apps/apps_db_quota_get.go --view expanded || true

printf '\nRelevant test file outlines:\n'
ast-grep outline shortcuts/apps/apps_db_execute_test.go --view expanded || true
printf '\n---\n'
ast-grep outline shortcuts/apps/apps_db_table_list_test.go --view expanded || true

printf '\nSearch for quota path/env parameter usage:\n'
rg -n 'appDbQuotaPath|dbEnvParams|env' shortcuts/apps/apps_db_quota_get.go shortcuts/apps/apps_db_execute_test.go shortcuts/apps/apps_db_table_list_test.go shortcuts/apps/*.go

Repository: larksuite/cli

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Read apps_db_quota_get.go around the Execute function:\n'
cat -n shortcuts/apps/apps_db_quota_get.go | sed -n '1,120p'

printf '\nRead relevant slices from db execute/table list tests:\n'
cat -n shortcuts/apps/apps_db_execute_test.go | sed -n '1,260p'
printf '\n---\n'
cat -n shortcuts/apps/apps_db_table_list_test.go | sed -n '1,260p'

Repository: larksuite/cli

Length of output: 26313


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Find all tests asserting env omission/default behavior in shortcuts/apps:\n'
rg -n -C 2 'omitempty|omit.*env|env parameter|Params\(dbEnvParams|dbEnvParams\(' shortcuts/apps/*test.go

printf '\nFind any direct tests for apps_db_quota_get command:\n'
rg -n -C 3 'quota-get|db_quota|get quota|appDbQuotaPath' shortcuts/apps/*test.go shortcuts/apps/*.go

Repository: larksuite/cli

Length of output: 12824


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the current implementation and nearby tests in small slices.
cat -n shortcuts/apps/apps_db_quota_get.go | sed -n '1,120p'

printf '\n--- apps_db_execute_test.go ---\n'
cat -n shortcuts/apps/apps_db_execute_test.go | sed -n '1,220p'

printf '\n--- apps_db_table_list_test.go ---\n'
cat -n shortcuts/apps/apps_db_table_list_test.go | sed -n '1,220p'

Repository: larksuite/cli

Length of output: 23339


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 3 'dbEnvParams|appDbQuotaPath|quota-get|db-quota-get|env' shortcuts/apps/apps_db_execute_test.go shortcuts/apps/apps_db_table_list_test.go shortcuts/apps/apps_db_quota_get.go shortcuts/apps/*test.go

Repository: larksuite/cli

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the db quota tests directly; focus on the two AppsDBQuotaGet cases.
cat -n shortcuts/apps/apps_db_env_recovery_quota_test.go | sed -n '297,360p'

printf '\nSearch for env omission assertions in quota tests:\n'
rg -n -C 2 'Params\["env"\]|omit|absent|not send|db-quota-get|AppsDBQuotaGet' shortcuts/apps/apps_db_env_recovery_quota_test.go

Repository: larksuite/cli

Length of output: 4779


Add a dry-run check for +db-quota-get's omitted env. The quota-get tests in shortcuts/apps/apps_db_env_recovery_quota_test.go cover output shape, but not that the request omits env when --environment is left unset.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/apps/apps_db_quota_get.go` around lines 44 - 51, The +db-quota-get
command currently builds its request without an explicit dry-run assertion for
the omitted env case. Update the quota-get flow in Execute and the related tests
so that when --environment is not provided, dbEnvParams receives an empty map
and the API request is verified to omit env entirely. Add this coverage
alongside the existing quota-get tests in apps_db_env_recovery_quota_test.go,
using appDbQuotaPath, dbEnvParams, and rctx.CallAPITyped as the key symbols to
locate the change.

Source: Coding guidelines

if err != nil {
return withAppsHint(err, appIDListHint)
}
Expand Down
4 changes: 2 additions & 2 deletions shortcuts/apps/apps_db_table_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var AppsDBTableGet = common.Shortcut{
Flags: append([]common.Flag{
{Name: "app-id", Desc: "app id", Required: true},
{Name: "table", Desc: "table name", Required: true},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -80,7 +80,7 @@ var AppsDBTableGet = common.Shortcut{
// CLI 检测 rctx.Format == "pretty" 时给 server 带 format=ddl,要求返 CREATE 语句文本;
// 其他 format(含默认 json)不传该参数,让 server 返默认结构化字段。
func buildDBTableGetParams(rctx *common.RuntimeContext) map[string]interface{} {
params := map[string]interface{}{"env": dbEnv(rctx)}
params := dbEnvParams(rctx, map[string]interface{}{})
if rctx.Format == "pretty" {
params["format"] = "ddl"
}
Expand Down
7 changes: 3 additions & 4 deletions shortcuts/apps/apps_db_table_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var AppsDBTableList = common.Shortcut{
{Name: "app-id", Desc: "app id", Required: true},
{Name: "page-size", Type: "int", Default: "20", Desc: "page size"},
{Name: "page-token", Desc: "pagination cursor from previous response"},
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
return err
Expand Down Expand Up @@ -110,10 +110,9 @@ func projectTableListItems(raw interface{}) []dbTableListItem {
}

func buildDBTableListParams(rctx *common.RuntimeContext) map[string]interface{} {
params := map[string]interface{}{
"env": dbEnv(rctx),
params := dbEnvParams(rctx, map[string]interface{}{
"page_size": rctx.Int("page-size"),
}
})
if token := strings.TrimSpace(rctx.Str("page-token")); token != "" {
params["page_token"] = token
}
Expand Down
10 changes: 10 additions & 0 deletions shortcuts/apps/db_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func dbEnv(rctx *common.RuntimeContext) string {
return rctx.Str("environment")
}

// dbEnvParams 把 env 并入 params:仅当显式指定了环境(非空)才带 env 键;未指定(空)时
// 省略该键,由服务端按应用多环境状态自动选分支(多环境→dev,单环境→online)。与家族对
// 空可选参数的 omit-empty 约定一致——不发空串,wire 上真正不带 env。原样返回同一个 map 便于链式。
func dbEnvParams(rctx *common.RuntimeContext, params map[string]interface{}) map[string]interface{} {
if env := dbEnv(rctx); env != "" {
params["env"] = env
}
return params
}

// rejectLegacyEnvFlag 在 Validate 阶段拦截已移除的 --env:显式传了就报清晰的 validation 错,指向 --environment。
func rejectLegacyEnvFlag(rctx *common.RuntimeContext) error {
if rctx.Changed("env") {
Expand Down
Loading
Loading