Skip to content

feat:udac cli#128

Merged
Episkey-G merged 2 commits into
ucloud:masterfrom
nzr1122:feat/udac
Jul 15, 2026
Merged

feat:udac cli#128
Episkey-G merged 2 commits into
ucloud:masterfrom
nzr1122:feat/udac

Conversation

@nzr1122

@nzr1122 nzr1122 commented Jul 14, 2026

Copy link
Copy Markdown

Features:
引入 udac cli
Fixes:

@Episkey-G

Copy link
Copy Markdown
Collaborator

cmd/products.gen.go不用手写
运行go run ./hack/gen-products后提交

@nzr1122

nzr1122 commented Jul 15, 2026

Copy link
Copy Markdown
Author

cmd/products.gen.go不用手写 运行go run ./hack/gen-products后提交

done

@Episkey-G Episkey-G left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

接入规范评审。硬性约束这边核过一轮,都没问题:check-product 规则 1-10 全过、两份 golden 齐全且重新生成后字节不变、cmd/products.gen.go 确认是 gen-products 生成的、鉴权全部走 cli.NewServiceClient、import 边界干净、输出通道没有自建 helper 也没有自行按 --output 分流、请求一律 client.NewGenericRequest() 构造。export / import 这两个非标准动词我认为是合理的,语义是「纳入/移出 UDAC 托管」,硬套 create/delete 反而误导。

有两处会导致静默失败的缺陷,见行内评论。

Comment thread products/udac/internal/udac/export.go Outdated
fmt.Fprintf(w, "%s[%s] exported successfully (type: %s, zone: %s)\n", productName, id, instanceType, zone)
}
}
ctx.EmitResult(cli.OpResultRow{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

--udb-idStringSliceVar(描述也写了 Repeatable.),但这里 EmitResult 只提交了 instanceIDs[0] 一行。上面 171-177 的 ProgressWriter 循环打印了全部 N 行,而 json/yaml 模式下 stdout 只会拿到第 1 个实例,退出码仍是 0 —— 调用方脚本会静默漏处理其余实例。

udac export --udb-id a --udb-id b -o json 的 stdout 只有 a。

规范 §5.3 的模板是循环内累积、收尾一次性提交:

results := make([]cli.OpResultRow, 0, len(instanceIDs))
for _, id := range instanceIDs {
    ...
    results = append(results, cli.OpResultRow{ResourceID: id, Action: "export", Status: "Exported"})
}
ctx.EmitResult(results...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

Comment thread products/udac/internal/udac/import.go Outdated
fmt.Fprintf(w, "%s[%s] imported successfully (type: %s, zone: %s)\n", productName, id, instanceType, zone)
}
}
ctx.EmitResult(cli.OpResultRow{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

export.go 的批量结果问题:--udb-id 可重复,但 EmitResult 只落 instanceIDs[0]udac import --udb-id a --udb-id b -o json 的 stdout 只有 a、退出码 0。改法一致,循环内累积 results 后收尾 ctx.EmitResult(results...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

// 6. 客户端过滤
rows := make([]importedInstanceRow, 0, len(instances))
for _, m := range instances {
if instanceID != "" && firstString(m, "ClusterId", "InstanceId", "ID") != instanceID {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

instanceID 直接来自 flag,没经过 ctx.PickResourceID,但 231-233 给这个 flag 注册了动态补全,而 provider 返回的是 id/name 形式(本文件 270 行 out = append(out, id+"/"+name))。

于是用户 udac list --udb-id <TAB> 补全出 udb-xxx/my-instance 之后,这里拿它跟 API 返回的裸 ID 比较必然不相等,全部被 continue 掉 —— 静默输出空表,退出码 0,没有任何提示。补全越好用,越容易踩。

同 PR 的 export.go:149-151 已经做了归一化,list 这里漏了。建议在过滤前补一行:

instanceID = ctx.PickResourceID(instanceID)

可参考 products/uhost/internal/uhost/list.go 对资源 ID flag 的处理。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

@Episkey-G Episkey-G merged commit 3e83dff into ucloud:master Jul 15, 2026
3 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants