feat(dacli): print/* 模块 wrapCommand 迁移 (create/delete/info/update, 10 exit 收口)

create 从旧 printCommandEnd 升级 (保留 auto-fix). delete/info/update process.exit → ctx.fail.
step machine 校验失败 → ctx.fail (聚合错误). print/ 模块 process.exit 归零.

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-07-21 21:07:48 +08:00
1 parent 2795d7f2db
commit 980dbedbbd
4 files changed
+224 -185

No files matched your search

+73 -83
View File
@@ -37,7 +37,7 @@ import {
getPrintDevList,
} from '../../webapi/printDev.ts'
import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix (S-X1/S-X2 silent + G-X1 suggest)
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ stdout 三模式 + CommandLog; v2.2+ wrapCommand 收口 5c
interface CreateOpts {
fullName: string
@@ -65,8 +65,7 @@ export function buildPrintCreateCommand(): Command {
.option('--visibleType <1|2>', '发布范围 (1=公开 2=权限设置, 仅 commonUse=1 时校验)', '1')
.option('--description <desc>', '说明 (Textarea)')
.option('--sortCode <n>', '排序码 (0-999999)', '0')
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
.option('--json', '原始 JSON 输出', false)
addOutputOptions(cmd)
.action(async (opts: CreateOpts) => {
// v2.1+ L1: stdout 三模式 — 默认 quiet, --verbose 全部输出, --json 原始 JSON
setupOutputFilter(opts)
@@ -74,96 +73,87 @@ export function buildPrintCreateCommand(): Command {
const startTime = Date.now()
// v2.1+ L2 silent+assertive+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1)
// - enCode 含 `-`/`_` 自动 strip (BS-新38 silent)
// - fullName 含 space/parens 自动 soften (BS-新52 silent)
// - 已有 printDev 重名 → suggest 加 `<appCode>` 前缀 (BS-47, 启用需 fetchExistingLists)
const fixCtx = await fetchExistingLists(c, c.appCode)
const cmdFix = runCommandAutoFix(opts as unknown as Record<string, unknown>, fixCtx)
if (cmdFix.silent.length > 0) {
Object.assign(opts, cmdFix.opts)
}
// v3.0+ step machine 校验 (3 step: 基础信息 + 数值范围 + 条件校验)
// 镜像 web printDev/Form.vue:29-92 schemas + ifShow 规则 (L65-77)
const validation = validatePrintCreate({
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
formId: opts.formId,
commonUse: opts.commonUse,
visibleType: opts.visibleType,
icon: opts.icon,
description: opts.description,
sortCode: opts.sortCode,
})
if (!validation.ok) {
for (const s of validation.steps) {
for (const e of s.errors) {
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
}
}
process.exit(1)
}
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
const body: Record<string, unknown> = {
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
type: opts.category === '1' ? 1 : 2,
enabledMark: 1,
sortCode: Number(opts.sortCode ?? 0),
}
if (opts.formId) body.moduleId = opts.formId
if (opts.commonUse !== undefined) body.commonUse = Number(opts.commonUse)
if (opts.visibleType !== undefined) body.visibleType = Number(opts.visibleType)
if (opts.icon) body.icon = opts.icon
if (opts.description) body.description = opts.description
// v3.0+ P0: 走 webapi/printDev.createPrintDev (web 端同名函数, 复用 query + body schema)
await initPrintDevWebapi(c)
const r = (await createPrintDev(body as any)) as { id?: string; code?: number; msg?: string }
const rCode = r.code ?? 200
if (rCode !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
// v2.1+ L3: 失败也落 CommandLog (供 AI 查 dacli log last 看回滚建议)
printCommandEnd({
command: 'print create',
appCode: c.appCode,
result: 'failure',
summary: { enCode: opts.enCode, fullName: opts.fullName },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
error: r.msg || `code=${rCode}`,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
process.exit(1)
}
let id = r.id
if (!id) {
// 兼容 webapi shim 解构 vs 不解构两种情况
const listR = (await getPrintDevList({ keyword: opts.enCode, pageSize: 50 })) as
| { list?: { id: string; enCode: string; fullName: string }[] }
| { id: string; enCode: string; fullName: string }[]
const list = Array.isArray(listR) ? listR : listR.list || []
const found = list.find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
log.ok(`✓ 打印模板创建成功 id=${id}`)
if (opts.json) printJson({ ...(r as object), id })
// v2.1+ L3: 落 CommandLog + 打印摘要 + "详情: dacli log last" 提示
printCommandEnd({
await wrapCommand({
command: 'print create',
appCode: c.appCode,
summary: { id, enCode: opts.enCode, category: opts.category, formId: opts.formId },
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
startTime,
verbose: opts.verbose,
json: opts.json,
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
}, async (ctx) => {
try {
// v3.0+ step machine 校验 (3 step: 基础信息 + 数值范围 + 条件校验)
// 镜像 web printDev/Form.vue:29-92 schemas + ifShow 规则 (L65-77)
const validation = validatePrintCreate({
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
formId: opts.formId,
commonUse: opts.commonUse,
visibleType: opts.visibleType,
icon: opts.icon,
description: opts.description,
sortCode: opts.sortCode,
})
if (!validation.ok) {
for (const s of validation.steps) {
for (const e of s.errors) {
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
}
}
return ctx.fail(
validation.steps.flatMap(s => s.errors).map(e => e.message).join('; '),
{ enCode: opts.enCode, fullName: opts.fullName },
)
}
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
const body: Record<string, unknown> = {
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
type: opts.category === '1' ? 1 : 2,
enabledMark: 1,
sortCode: Number(opts.sortCode ?? 0),
}
if (opts.formId) body.moduleId = opts.formId
if (opts.commonUse !== undefined) body.commonUse = Number(opts.commonUse)
if (opts.visibleType !== undefined) body.visibleType = Number(opts.visibleType)
if (opts.icon) body.icon = opts.icon
if (opts.description) body.description = opts.description
// v3.0+ P0: 走 webapi/printDev.createPrintDev (web 端同名函数, 复用 query + body schema)
await initPrintDevWebapi(c)
const r = (await createPrintDev(body as any)) as { id?: string; code?: number; msg?: string }
const rCode = r.code ?? 200
if (rCode !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
return ctx.fail(r.msg || `code=${rCode}`, { enCode: opts.enCode, fullName: opts.fullName })
}
let id = r.id
if (!id) {
// 兼容 webapi shim 解构 vs 不解构两种情况
const listR = (await getPrintDevList({ keyword: opts.enCode, pageSize: 50 })) as
| { list?: { id: string; enCode: string; fullName: string }[] }
| { id: string; enCode: string; fullName: string }[]
const list = Array.isArray(listR) ? listR : listR.list || []
const found = list.find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
log.ok(`✓ 打印模板创建成功 id=${id}`)
if (opts.json) printJson({ ...(r as object), id })
ctx.success({ id, enCode: opts.enCode, category: opts.category, formId: opts.formId })
} catch (e) {
ctx.fail(`print create 失败: ${(e as Error).message?.slice(0, 200)}`)
}
})
})
installHelpHook(cmd, {
+43 -27
View File
@@ -20,11 +20,14 @@ import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { initWebapi as initPrintDevWebapi, loadPrintDev } from '../../webapi/printDev.ts'
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
interface DeleteOpts {
id: string
yes?: boolean
json?: boolean
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
verbose?: boolean
}
export function buildPrintDeleteCommand(): Command {
@@ -32,36 +35,49 @@ export function buildPrintDeleteCommand(): Command {
.description('删除打印模板 (v0.15+ 镜像 web 端 delPrintDev, 走 /api/system/printDev/{id})')
.requiredOption('--id <id>', '打印模板 id')
.option('--yes', '跳过 TTY 确认 (强制删除)', false)
.option('--json', '原始 JSON 输出', false)
addOutputOptions(cmd)
.action(async (opts: DeleteOpts) => {
// v0.15+ (P0-9): id 数字校验 (跟 portal/role 一致)
const idRegex = /^\d{10,30}$/
if (!idRegex.test(opts.id)) {
log.error(`--id "${opts.id}" 不是合法 JNPF id (期望纯数字 10-30 位)`)
log.error('提示: 用 `dacli print list` 查 id, 别传 fullName/enCode')
process.exit(1)
}
// v0.15+ TTY 确认 (跟 report delete 一致)
if (!opts.yes && process.stdin.isTTY) {
log.warn(`即将删除打印模板 id=${opts.id}, 此操作不可恢复`)
log.warn(' 提示: 加 --yes 跳过确认 (AI/脚本场景)')
process.exit(1)
}
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
await initPrintDevWebapi(c)
// 镜像 web 端 delPrintDev(id) → defHttp.delete
const r = (await loadPrintDev.delPrintDev(opts.id)) as { code?: number; msg?: string }
if (r && r.code !== undefined && r.code !== 200) {
log.error(`print delete 失败 (code=${r.code}): ${r.msg}`)
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
process.exit(1)
}
log.ok(`✓ 打印模板已删除 id=${opts.id} (v0.15+ webapi 镜像)`)
if (opts.json) printJson({ id: opts.id, code: 200, msg: '删除成功' })
await wrapCommand({
command: 'print delete',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
// v0.15+ (P0-9): id 数字校验 (跟 portal/role 一致)
const idRegex = /^\d{10,30}$/
if (!idRegex.test(opts.id)) {
log.error('提示: 用 `dacli print list` 查 id, 别传 fullName/enCode')
return ctx.fail(`--id "${opts.id}" 不是合法 JNPF id (期望纯数字 10-30 位)`, { id: opts.id })
}
// v0.15+ TTY 确认 (跟 report delete 一致)
if (!opts.yes && process.stdin.isTTY) {
log.warn(' 提示: 加 --yes 跳过确认 (AI/脚本场景)')
return ctx.fail(`即将删除打印模板 id=${opts.id}, 此操作不可恢复 (加 --yes 确认)`, { id: opts.id })
}
await initPrintDevWebapi(c)
// 镜像 web 端 delPrintDev(id) → defHttp.delete
const r = (await loadPrintDev.delPrintDev(opts.id)) as { code?: number; msg?: string }
if (r && r.code !== undefined && r.code !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
return ctx.fail(`print delete 失败 (code=${r.code}): ${r.msg}`, { id: opts.id, code: r.code })
}
log.ok(`✓ 打印模板已删除 id=${opts.id} (v0.15+ webapi 镜像)`)
if (opts.json) printJson({ id: opts.id, code: 200, msg: '删除成功' })
ctx.success({ id: opts.id })
} catch (e) {
ctx.fail(`print delete 失败: ${(e as Error).message?.slice(0, 200)}`)
}
})
})
installHelpHook(cmd, {
purpose: '删除打印模板 (v0.15+ 镜像 web delPrintDev)',
+38 -23
View File
@@ -14,43 +14,58 @@ import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { initWebapi as initPrintDevWebapi, getPrintDevInfo } from '../../webapi/printDev.ts'
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
interface InfoOpts {
id: string
json?: boolean
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
verbose?: boolean
}
export function buildPrintInfoCommand(): Command {
const cmd = new Command('info')
.description('查看打印模板详情 (含版本/打印配置)')
.requiredOption('--id <id>', '打印模板 id')
.option('--json', '原始 JSON 输出', false)
addOutputOptions(cmd)
.action(async (opts: InfoOpts) => {
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
// v3.0+ 调用 webapi/printDev.initWebapi → loadPrintDev.getPrintDevInfo
await initPrintDevWebapi(c)
try {
// shim 已 unwrap 信封 (code 错误会直接 throw), 直接拿 data
const d = (await getPrintDevInfo(opts.id)) as Record<string, unknown>
if (!d || (d as { id?: string }).id === undefined) {
const enhanced = enhanceFromBackend('打印模板 id 不存在', 'id', { entity: 'print' })
await wrapCommand({
command: 'print info',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
// v3.0+ 调用 webapi/printDev.initWebapi → loadPrintDev.getPrintDevInfo
await initPrintDevWebapi(c)
try {
// shim 已 unwrap 信封 (code 错误会直接 throw), 直接拿 data
const d = (await getPrintDevInfo(opts.id)) as Record<string, unknown>
if (!d || (d as { id?: string }).id === undefined) {
const enhanced = enhanceFromBackend('打印模板 id 不存在', 'id', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
return ctx.fail(`print info 失败: 打印模板 id=${opts.id} 不存在`, { id: opts.id })
}
if (opts.json) {
printJson(d)
return ctx.success({ id: opts.id })
}
log.info(`打印模板 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
console.log(`category: ${d.category}`)
console.log(`type: ${d.type}`)
console.log(`state: ${d.state === 1 ? '已发布' : '未发布'}`)
ctx.success({ id: opts.id, enCode: d.enCode })
} catch (e: any) {
// shim 已 throw, 这里 catch 后给友好提示
const enhanced = enhanceFromBackend(e?.message ?? String(e), 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
process.exit(1)
ctx.fail(`print info 失败: ${(e as Error).message?.slice(0, 200)}`, { id: opts.id })
}
if (opts.json) {
printJson(d)
return
}
log.info(`打印模板 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
console.log(`category: ${d.category}`)
console.log(`type: ${d.type}`)
console.log(`state: ${d.state === 1 ? '已发布' : '未发布'}`)
} catch (e: any) {
// shim 已 throw, 这里 catch 后给友好提示
const enhanced = enhanceFromBackend(e?.message ?? String(e), 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
process.exit(1)
}
})
})
installHelpHook(cmd, {
purpose: '查看打印模板详情',
+70 -52
View File
@@ -23,6 +23,7 @@ import {
loadPrintDev,
} from '../../webapi/printDev.ts'
import { validatePrintCreate } from './_validate.ts'
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c
interface UpdateOpts {
id: string
@@ -38,6 +39,8 @@ interface UpdateOpts {
formId?: string
description?: string
json?: boolean
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
verbose?: boolean
}
/** PrintCrForm 字段 (跟 create 一致, 镜像 web 端 updatePrintDev body) */
@@ -71,64 +74,79 @@ export function buildPrintUpdateCommand(): Command {
.option('--icon <i>', '图标 (commonUse=1 时必填)')
.option('--formId <id>', '绑定的表单 id (type=2 必填)')
.option('--description <d>', '说明')
.option('--json', '原始 JSON 输出', false)
addOutputOptions(cmd)
.action(async (opts: UpdateOpts) => {
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
await initPrintDevWebapi(c)
// 1. 拉原 print 模板 (跟 web 一致: getPrintDevInfo 拿全字段)
const orig = (await loadPrintDev.getPrintDevInfo(opts.id)) as PrintForm
if (!orig || !orig.id) {
log.error(`print update 失败: 拉原模板 id=${opts.id} 失败`)
process.exit(1)
}
await wrapCommand({
command: 'print update',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
await initPrintDevWebapi(c)
// 2. step machine 校验 (校验 user-provided 字段, 跟 create 行为一致)
// 校验失败 exit 1, 跟其他 create/update 命令对齐
const toValidate: Record<string, unknown> = {}
if (opts.fullName !== undefined) toValidate.fullName = opts.fullName
if (opts.enCode !== undefined) toValidate.enCode = opts.enCode
if (opts.category !== undefined) toValidate.category = opts.category
if (opts.commonUse !== undefined) toValidate.commonUse = Number(opts.commonUse)
if (opts.visibleType !== undefined) toValidate.visibleType = Number(opts.visibleType)
if (opts.icon !== undefined) toValidate.icon = opts.icon
if (opts.formId !== undefined) toValidate.formId = opts.formId
if (Object.keys(toValidate).length > 0) {
const v = validatePrintCreate(toValidate as Parameters<typeof validatePrintCreate>[0])
if (!v.ok) {
// 遍历所有 step 收集错误
for (const step of v.steps) {
for (const err of step.errors) log.error(` [${step.stepName}] ${err.message}`)
// 1. 拉原 print 模板 (跟 web 一致: getPrintDevInfo 拿全字段)
const orig = (await loadPrintDev.getPrintDevInfo(opts.id)) as PrintForm
if (!orig || !orig.id) {
return ctx.fail(`print update 失败: 拉原模板 id=${opts.id} 失败`, { id: opts.id })
}
process.exit(1)
// 2. step machine 校验 (校验 user-provided 字段, 跟 create 行为一致)
const toValidate: Record<string, unknown> = {}
if (opts.fullName !== undefined) toValidate.fullName = opts.fullName
if (opts.enCode !== undefined) toValidate.enCode = opts.enCode
if (opts.category !== undefined) toValidate.category = opts.category
if (opts.commonUse !== undefined) toValidate.commonUse = Number(opts.commonUse)
if (opts.visibleType !== undefined) toValidate.visibleType = Number(opts.visibleType)
if (opts.icon !== undefined) toValidate.icon = opts.icon
if (opts.formId !== undefined) toValidate.formId = opts.formId
if (Object.keys(toValidate).length > 0) {
const v = validatePrintCreate(toValidate as Parameters<typeof validatePrintCreate>[0])
if (!v.ok) {
// 遍历所有 step 收集错误
for (const step of v.steps) {
for (const err of step.errors) log.error(` [${step.stepName}] ${err.message}`)
}
return ctx.fail(
v.steps.flatMap(s => s.errors).map(e => e.message).join('; '),
{ id: opts.id },
)
}
}
// 3. 构造 body (跟 web 端 handleSubmit 一致, spread orig 覆盖用户输入)
const body: Record<string, unknown> = { ...orig, id: opts.id }
if (opts.fullName !== undefined) body.fullName = opts.fullName
if (opts.enCode !== undefined) body.enCode = opts.enCode
if (opts.category !== undefined) body.category = opts.category
if (opts.type !== undefined) body.type = Number(opts.type)
if (opts.sortCode !== undefined) body.sortCode = Number(opts.sortCode)
if (opts.enabledMark !== undefined) body.enabledMark = Number(opts.enabledMark)
if (opts.commonUse !== undefined) body.commonUse = Number(opts.commonUse)
if (opts.visibleType !== undefined) body.visibleType = Number(opts.visibleType)
if (opts.icon !== undefined) body.icon = opts.icon
if (opts.formId !== undefined) body.formId = opts.formId
if (opts.description !== undefined) body.description = opts.description
// 4. 调 webapi updatePrintDev (走 web 端镜像, 端点 /api/system/printDev/{id})
const r = (await loadPrintDev.updatePrintDev(body)) as { code?: number; msg?: string }
if (r && r.code !== undefined && r.code !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
return ctx.fail(`print update 失败 (code=${r.code}): ${r.msg}`, { id: opts.id, code: r.code })
}
log.ok(`✓ 打印模板修改成功 id=${opts.id} enCode=${body.enCode}`)
if (opts.json) printJson({ id: opts.id, code: 200, msg: '更新成功', raw: r })
ctx.success({ id: opts.id, enCode: body.enCode })
} catch (e) {
ctx.fail(`print update 失败: ${(e as Error).message?.slice(0, 200)}`)
}
}
// 3. 构造 body (跟 web 端 handleSubmit 一致, spread orig 覆盖用户输入)
// 后端 PrintUpForm 必填所有字段, 跟 update 一致先 getPrintDevInfo 拿全字段
const body: Record<string, unknown> = { ...orig, id: opts.id }
if (opts.fullName !== undefined) body.fullName = opts.fullName
if (opts.enCode !== undefined) body.enCode = opts.enCode
if (opts.category !== undefined) body.category = opts.category
if (opts.type !== undefined) body.type = Number(opts.type)
if (opts.sortCode !== undefined) body.sortCode = Number(opts.sortCode)
if (opts.enabledMark !== undefined) body.enabledMark = Number(opts.enabledMark)
if (opts.commonUse !== undefined) body.commonUse = Number(opts.commonUse)
if (opts.visibleType !== undefined) body.visibleType = Number(opts.visibleType)
if (opts.icon !== undefined) body.icon = opts.icon
if (opts.formId !== undefined) body.formId = opts.formId
if (opts.description !== undefined) body.description = opts.description
// 4. 调 webapi updatePrintDev (走 web 端镜像, 端点 /api/system/printDev/{id})
const r = (await loadPrintDev.updatePrintDev(body)) as { code?: number; msg?: string }
if (r && r.code !== undefined && r.code !== 200) {
log.error(`print update 失败 (code=${r.code}): ${r.msg}`)
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
process.exit(1)
}
log.ok(`✓ 打印模板修改成功 id=${opts.id} enCode=${body.enCode}`)
if (opts.json) printJson({ id: opts.id, code: 200, msg: '更新成功', raw: r })
})
})
installHelpHook(cmd, {
purpose: '修改打印模板 (v0.15+ 镜像 web 端 updatePrintDev)',