用途:该技能面向使用 BoxLang 编写命令行脚本与类,涵盖文件运行、参数解析、REPL 交互以及编译、转译、审计等操作。
支持的文件类型:.bx(类,入口为 main(args=[]) 方法)、.bxs(脚本,顶层代码)、.bxm(模板,顶层标记/代码)、.cfs/.cfm(经 bx-compat-cfml 的 CFML,顶层代码)、带 shebang 的 .sh(#!/usr/bin/env boxlang)。
运行方式:boxlang MyApp.bx 运行类;boxlang process.bxs --config=prod.json --debug 运行脚本;boxlang render.bxm 运行模板;boxlang --bx-code "println( 'Hello!' )" 执行内联代码;管道输入 echo "println( 'piped!' )" | boxlang;不带参数进入 REPL。
参数解析:通过 CLIGetArgs() 或 server.cli.parsed 获取 { options, positionals }。支持 --option(true)、--option=value、--option="value"、-o=value、-o(true)、--!option 与 --no-option(false)、-abc(a/b/c 均为 true)。
内置函数:CLIGetArgs() 返回解析结果;CLIRead([prompt]) 读取一行输入;CLIClear() 清屏;CLIExit([exitCode=0]) 退出。可配合 fileExists 等做校验。
CLI 标志:--bx-debug/BOXLANG_DEBUG、--bx-config/BOXLANG_CONFIG、--bx-home/BOXLANG_HOME、--bx-code、--bx-printAST、--bx-transpile。
Action 命令:compile、cftranspile、featureaudit 均支持 --source、--target、--recurse;schedule 运行调度文件(.bx 类,Ctrl+C 结束)。
运行时检测:server.boxlang.cliMode、jarMode、runtimeHome、server.coldfusion.productVersion;CLI 模式可用 application、request、server、server.cli、server.cli.parsed 作用域。
REPL:支持多行输入、:history、:clear、:dark/:light、Ctrl+C 退出,!! 重复上条、!n 重复第 n 条。
约定做法:用 CLIGetArgs() 而非原始 args;校验必填参数并 CLIExit(1);用 --bx-config 分离配置;用 .bx 类的 main() 作为可复用入口;脚本加 shebang 后 chmod +x 直接执行;交互提示用 CLIRead()。
限制:资料未说明版本要求、平台支持、性能上限、异常细节及授权/收费信息,暂未提供。