资讯动态

Miller 内置在线帮助系统完全指南:`mlr help`、REPL `:help` 与机器可读目录

发布时间:2026/9/24 19:57:40 来源:尧图企业网站定制
CLI数据分析【免费下载链接】millerMiller is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON项目地址https://gitcode.com/gh_mirrors/mi/miller点击查看免费下载导读MillerGitHub 加速计划 / mi / miller是面向 CSV、TSV、制表 JSON 等按名索引数据的类awk/sed/cut/join/sort命令行工具。它内置了一套多层次的在线帮助机制——从入口级用法摘要mlr --help到按主题分发的mlr help topics再到针对单个 verb、flag、DSL 函数的精确/近似检索以及 REPL 内的:help、传统man mlr手册页最后还包括供 AI Agent 和工具链消费的--as-json机器可读目录与mlr which意图路由。读完本文你将掌握 Miller 全部在线帮助入口的用法、主题分类、快捷键、精确与模糊检索语义以及如何用结构化 JSON 目录驱动自动化脚本。帮助系统的整体框架Miller 的帮助体系由 pkg/terminals/help 包实现它是 Miller「terminals 终端框架」参见 pkg/terminals中的一员与 REPLmlr repl、回归测试入口mlr regtest并列。核心是一个「主题 → 处理器」的查找表tHandlerLookupTable在包级init()中按分区注册了全部主题处理器见 entry.goEssentialstopics、basic-examples、file-formatsFlagsflags、flag、list-separator-aliases、list-separator-regex-aliases以及从cli.FLAG_TABLE动态生成的各 flag 分区主题如csv-only-flags、json-only-flagsVerbslist-verbs、usage-verbs、verbFunctionslist-functions、list-function-classes、list-functions-in-class、usage-functions、usage-functions-by-class、functionKeywordslist-keywords、usage-keywords、keywordOtherauxents、terminals、mlrrc、output-colorization、type-arithmetic-info、type-arithmetic-info-extended。除此之外还有一个internal: true的「Internal/docgen」分区专供 Web 文档与 manpage 自动生成脚本使用如list-functions-as-table、show-help-for-section不会出现在交互式用户可见的主题列表中。主帮助入口mlr --help与mlr help topics前门mlr --help或mlr -h最直接的入口是mlr --help其同义形式是mlr -h输出整体用法Usage: mlr [flags] [verb] [verb-dependent options ...] {zero or more file names} If no verb is given, cat is used, which is handy for format conversions, e.g. mlr --c2j example.csv If zero file names are provided, standard input is read, e.g. mlr --csv sort -f shape example.csv Output of one verb may be chained as input to another using then, e.g. mlr --csv stats1 -a min,mean,max -f quantity then sort -f color example.csv Please see mlr help topics for more information.这段输出直接来自源码中的MainUsage()见 entry.go它简明地概括了 Miller 的三个核心调用范式无 verb 时默认用cat适合格式转换、不提供文件名时读标准输入、用then将多个 verb 串联成管道。-h/--help的短路处理由ParseTerminalUsage()完成见 entry.go。主题总览mlr help topicsmlr help topics是后续所有帮助的分发中枢列出全部可查主题Type mlr help {topic} for any of the following: Essentials: mlr help topics mlr help basic-examples mlr help file-formats Flags: mlr help flags mlr help flag mlr help list-separator-aliases mlr help list-separator-regex-aliases mlr help comments-in-data-flags mlr help compressed-data-flags mlr help csv/tsv-only-flags mlr help dkvp-only-flags mlr help file-format-flags mlr help flatten-unflatten-flags mlr help format-conversion-keystroke-saver-flags mlr help json-only-flags mlr help legacy-flags mlr help markdown-only-flags mlr help miscellaneous-flags mlr help output-colorization-flags mlr help pprint-only-flags mlr help profiling-flags mlr help separator-flags Verbs: mlr help list-verbs mlr help usage-verbs mlr help verb Functions: mlr help list-functions mlr help list-function-classes mlr help list-functions-in-class mlr help usage-functions mlr help usage-functions-by-class mlr help function Keywords: mlr help list-keywords mlr help usage-keywords mlr help keyword Other: mlr help auxents mlr help terminals mlr help mlrrc mlr help output-colorization mlr help type-arithmetic-info mlr help type-arithmetic-info-extended Shorthands: mlr -g mlr help flags mlr -l mlr help list-verbs mlr -L mlr help usage-verbs mlr -f mlr help list-functions mlr -F mlr help usage-functions mlr -k mlr help list-keywords mlr -K mlr help usage-keywords Lastly, mlr help ... will search for your exact text ... using the sources of mlr help flag, mlr help verb, mlr help function, and mlr help keyword. Use mlr help find ... for approximate (substring) matches, e.g. mlr help find map for all things with map in their names.值得注意的两点Flag 分区主题是动态生成的。像csv-only-flags、json-only-flags这样的主题源码里并没有手工逐条写入而是在init()中遍历cli.FLAG_TABLE.GetDowndashSectionNames()把每个 flag 分区的名称「降横线化」空格替换为连字符、转小写后动态注册进查找表见 entry.go保证帮助主题与实际的 flag 表定义永不脱节。快捷键-g、-l、-L、-f、-F、-k、-K分别等价于对应的长形式例如mlr -l就是mlr help list-verbs。这组映射定义在shorthandLookupTable中见 entry.go由ParseTerminalUsage()在 CLI 解析阶段短路处理不经过mlr help主流程。辅助主题基础示例与文件格式mlr help basic-examples直接打印一组可复制的入门命令见 entry.gomlr --icsv --opprint cat example.csv、mlr --icsv --opprint sort -f shape example.csv、mlr --icsv --opprint cut -f flag,shape example.csv、mlr --csv filter $color red example.csv、mlr --icsv --ojson put $ratio $quantity / $rate example.csv、以及用--from与then链式组合的mlr --icsv --opprint --from example.csv sort -nr index then cut -f shape,quantity。mlr help file-formats以 ASCII 示意图讲解 CSV/CSV-lite、TSV、JSON对象数组、JSON Lines、YAML、PPRINT、Markdown 表格、XTAB、DKVP、DKVPX、NIDX、DCF 等全部输入格式如何映射为「键:值」记录见 entry.go。精确检索mlr help {名称}当你知道要找的东西的名字时直接用mlr help后跟名称例如mlr help mapmap: declares a map-valued local variable in the current curly-braced scope. Type-checking happens at assignment: map b 0 is an error. map b {} is always OK. map b a is OK or not depending on whether a is a map.其底层是helpByExactSearch()对每个查询词依次尝试 flag 表、transformerverb表、DSL 内建函数表、关键字表四处查找任意一处命中即输出见 entry.go。这也是为什么「sec2gmt」既是 verb 名又是 DSL 函数名时能够同时得到两类信息——它们分属不同注册表。近似检索mlr help find {子串}如果你只记得名称的一部分用mlr help find做不区分大小写的子串搜索。例如mlr help find gmt会返回所有名字或说明中包含 gmt 的条目——包括sec2gmtdate、sec2gmtverb 与函数、gmt2localtime、gmt2nsec、gmt2sec、localtime2gmt、nsec2gmt、nsec2gmtdate等每条都带完整用法与示例sec2gmtdate Usage: mlr sec2gmtdate {comma-separated list of field names} Replaces a numeric field representing seconds since the epoch with the corresponding GMT year-month-day timestamp; leaves non-numbers as-is. This is nothing more than a keystroke-saver for the sec2gmtdate function: mlr sec2gmtdate time1,time2 is the same as mlr put $time1sec2gmtdate($time1);$time2sec2gmtdate($time2) Options: -h|--help Show this message. sec2gmt Usage: mlr sec2gmt [options] {comma-separated list of field names} Replaces a numeric field representing seconds since the epoch with the corresponding GMT timestamp; leaves non-numbers as-is. This is nothing more than a keystroke-saver for the sec2gmt function: mlr sec2gmt time1,time2 is the same as mlr put $time1 sec2gmt($time1); $time2 sec2gmt($time2) Options: -1 Format seconds with 1 decimal place. ... --millis Input numbers are treated as milliseconds since the epoch. --micros Input numbers are treated as microseconds since the epoch. --nanos Input numbers are treated as nanoseconds since the epoch. -h|--help Show this message. gmt2localtime (classtime #args1,2) Convert from a GMT-time string to a local-time string. Consulting $TZ unless second argument is supplied. Examples: gmt2localtime(1999-12-31T22:00:00Z) 2000-01-01 00:00:00 with TZAsia/Istanbul ...mlr help find的实现是helpByApproximateSearch()同样覆盖 flag、verb、函数、关键字四类注册表但匹配语义从「精确名称匹配」换成「子串包含」见 entry.go。这正是《DSL 内建函数参考》所收录内容的命令行投影。按类目检索flag、verb、函数、关键字Flagmlr help flags与mlr help flag {名称}mlr help flags是 命令行 flag 列表 的完整命令行版本直接调用cli.FLAG_TABLE.ShowHelp()输出全部 flag见 entry.go。mlr help flag {flag名}则精确查询单个 flag如mlr help flag --csv查不到时输出Not found.。Verbmlr -l、mlr cat --help、mlr help verb sortmlr help list-verbs快捷键mlr -l列出全部 verb 名。其输出会随 stdout 是否为终端而自适应交互终端里以段落形式换行打印管道/重定向时则垂直一行一个见 entry.go方便脚本解析。单个 verb 可以用--help/-h直接查也可以走mlr help verb。例如mlr cat --helpUsage: mlr cat [options] Passes input records directly to output. Most useful for format conversion. Options: -n Prepend field n to each record with record-counter starting at 1. -N {name} Prepend field {name} to each record with record-counter starting at 1. -g {a,b,c} Optional group-by-field names for counters, e.g. a,b,c. --filename Prepend current filename to each record. --filenum Prepend current filenum (1-up) to each record. -h|--help Show this message.再如mlr group-like -hUsage: mlr group-like [options] Outputs records in batches having identical field names. Options: -h|--help Show this message.而mlr help verb sort则给出更完整的排序语义说明与参数表来自 sort 变换器sort Usage: mlr sort {flags} Sorts records primarily by the first specified field, secondarily by the second field, and so on. (Any records not having all specified sort keys will appear at the end of the output, in the order they were encountered, regardless of the specified sort order.) The sort is stable: records that compare equal will sort in the order they were encountered in the input record stream. Options: -f {a,b,c} Lexical ascending sort on the specified field names. -r {a,b,c} Lexical descending sort on the specified field names. -c {a,b,c} Case-folded lexical ascending sort on the specified field names. -cr {a,b,c} Case-folded lexical descending sort on the specified field names. -n {a,b,c} Numerical ascending sort on the specified field names; nulls sort last. -nf {a,b,c} Same as -n. -nr {a,b,c} Numerical descending sort on the specified field names; nulls sort first. -t {a,b,c} Natural ascending sort on the specified field names. -b Move sort fields to start of record, as in reorder -b. -tr|-rt {a,b,c} Natural descending sort on the specified field names. -h|--help Show this message. Example: mlr sort -f a,b -nr x,y,z which is the same as: mlr sort -f a -f b -nr x -nr y -nr zverb 帮助由transformers.ShowHelpForTransformer()驱动见 entry.go查询不存在的 verb 时会提示mlr help list-verbs。更完整的 verb 清单见 verb 参考。函数mlr -f、mlr help function {名称}DSL 内建函数的帮助入口包括mlr help list-functions快捷键mlr -f列出全部函数名同样区分终端/管道两种排版mlr help list-function-classes列出函数类别如 time、collections、conversion 等mlr help list-functions-in-class {类名}列出指定类别下的函数mlr help usage-functions快捷键mlr -F按类列出全部函数与用法mlr help function {名称}查询单个函数。例如mlr help function appendappend (classcollections #args2) Appends second argument to end of first argument, which must be an array.又如mlr help function splitasplita (classconversion #args2) Splits string into array with type inference. First argument is string to split; second is the separator to split on. Example: splita(3,4,5, ,) [3,4,5]注意mlr help function split会输出Function split not found.——因为 Miller 内建的是splita返回数组而非split这恰好演示了帮助系统「找不到就如实报告、并提示你换用近似检索」的行为。函数注册表实现在 pkg/dsl/cst完整清单见 DSL 内建函数参考。关键字mlr help keyword {关键字}DSL 关键字如map、for、if、while等由mlr help list-keywords快捷键mlr -k与mlr help keyword {关键字}查询usage-keywords快捷键mlr -K给出全部关键字的用法。控制结构、变量作用域等语法细节可对照 DSL 控制结构参考。REPL 内的在线帮助:help与:h进入交互式 REPLmlr repl后可以在提示符下输入:h或:help查看在线帮助$ mlr repl Miller v6.0.0-dev REPL for darwin:amd64:go1.16.5 Docs: https://miller.readthedocs.io Type :h or :help for on-line help; :q or :quit to quit. [mlr] :h Options: :help intro :help examples :help repl-list :help repl-details :help prompt :help function-names :help function-details :help {function name}, e.g. :help sec2gmt :help {function name}, e.g. :help sec2gmt [mlr]REPL 的设计原则是任何 Miller DSL 表达式可直接在提示符下求值而以:开头的非 DSL 语句如:help、:quit、:open由 REPL 自身的 verb 处理器分发见 pkg/terminals/repl/README.md 与 verbs.go。REPL 的完整介绍见 REPL 文档。传统手册页man mlr如果你通过包管理器安装 Miller通常直接就有man mlr提供传统 Unix 手册页。即便没有也不必担心——该手册页本质上就是把mlr help topics各主题的信息拼接在一起。仓库中 man/Makefile 展示了生成链路由../mlr二进制自动生成manpage.txt再经./mkman.rb | groff -man -Tascii | col -b | expand -8排版成最终手册并同步拷贝到 docs/src/manpage.txt。在线副本见 Manual page。面向 Agent 的机器可读目录mlr help --as-json除了人读的纯文本Miller 还提供结构化 JSON 输出专门服务于 AI Agent、脚本与工具链避免它们去刮取人读散文。启用方式与输出形态两种等价开关见 entry_json.go在mlr help ...命令行任意位置加--as-json或设置环境变量MLR_HELP_JSON为真值1、true、yes大小写不敏感。不带主题时输出完整目录CatalogForJSON包含四个字段见 entry_json.go字段含义mlr_versionMiller 版本号catalog_schema_version目录结构版本当前为2结构变更时递增verbs全部 verb 的结构化信息名称、摘要、用法文本等functions全部 DSL 内建函数flags全部命令行 flagkeywords全部 DSL 关键字mlr_version与catalog_schema_version合起来可作为缓存键两者任一变化才需要重新拉取。轻量索引mlr help --as-json --index带--index时输出精简的能力索引IndexEntryForJSON每条只有kind、name、summary三字段见 entry_json.go并按 kindverb function flag keyword与名称排序输出确定、可 diff适合先快速扫描全貌再深入个别条目。按主题筛选mlr help --as-json {topic} [{names...}]mlr help --as-json verb、function、flag、keyword四种主题各可取全部或按名称取部分条目见 entry_json.go。例如mlr help --as-json function sec2gmt,sec2gmtdate只返回这两个函数的 JSON 描述。这套机器可读目录不止服务于命令行BuildFullCatalog()、BuildIndex()等导出 API见 api.go同时被mlr mcp服务器复用让同一份目录/索引/检索能力通过 MCP 协议对外提供见 MCP 服务器文档。意图路由mlr which 自然语言查询mlr which是一个为 AI Agent 与交互用户设计的「意图 → 能力」路由器输入一句自然语言查询它检索 verb/函数/flag/关键字四类目录并输出按得分降序排列的 JSON 数组每项含kind、name、score、summary同时用退出码表达置信度见 entry_which.go退出码0至少一个结果的名称命中了查询词高置信匹配退出码1用法/参数错误例如没有给查询、或给了--help退出码2没有任何结果在名称层面命中低置信但结果数组仍然输出、仍然可用。这样 Agent 可以只看退出码做分支而不必解析散文。评分机制见 entry_which.go为每个 token 计分名称命中每个 token 得 20 分whichNameMatchScore正文摘要/用法文本命中每个 token 得 5 分匹配为不区分大小写的子串匹配。查询先经whichTokenize()清洗转小写、按非单词字符切分、丢弃单字符 token 与停用词a、the、to、and、how、get、use等见 entry_which.go并去重。排序时同分按 kind 优先级verb 优先再按名称字母序保证结果稳定可预期。帮助系统的自检与文档生成值得注意的是这套帮助系统不仅是运行时功能还承担着文档一致性的保障与文档生成职责自检内部主题flagTableNilCheck在回归测试语境下调用cli.FLAG_TABLE.NilCheck()确保 flag 表没有任何 flag 缺失帮助字符串见 entry.go文档生成「Internal/docgen」分区中的list-verbs-as-paragraph、list-functions-as-table、show-help-for-section等内部主题把各注册表的层次结构暴露到标准输出由 docs 与 man 目录下的 Ruby 自动生成脚本如mkman.rb驱动循环与排版实现「一份注册表、多处文档同源」。这也是mlr help输出的内容与 reference-verbs、reference-dsl-builtin-functions、reference-main-flag-list、glossary、release-docs 等页面保持一致的根本原因。速查与最佳实践需求命令整体用法mlr --help/mlr -h全部主题mlr help topics全部 flagmlr help flags/mlr -g单个 flagmlr help flag --csv全部 verbmlr help list-verbs/mlr -l单个 verbmlr help verb sort或mlr sort --help全部函数mlr help list-functions/mlr -f单个函数mlr help function sec2gmt函数类别mlr help list-function-classes、mlr help list-functions-in-class time全部/单个关键字mlr help list-keywords/mlr -kmlr help keyword map精确检索任意名称mlr help {名称}自动搜 flag/verb/函数/关键字子串近似检索mlr help find gmtREPL 内帮助mlr repl后输入:h/:help传统手册页man mlr在线副本见 manpage.md完整 JSON 目录mlr help --as-json轻量 JSON 索引mlr help --as-json --index按主题 JSON 筛选mlr help --as-json function sec2gmt自然语言意图路由mlr which convert seconds to gmt实操建议日常交互优先使用mlr help find做模糊定位再用mlr help {verb|function|flag|keyword}精确展开编写脚本或训练 Agent 时使用mlr help --as-json与mlr which并借助catalog_schema_version做缓存失效判断。所有帮助内容均可在运行mlr的任意环境离线获取不依赖网络文档。赞分享CLI数据分析【免费下载链接】millerMiller is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON项目地址https://gitcode.com/gh_mirrors/mi/miller点击查看免费下载相关推荐Miller AI 支持内部机制全解析mlr help --as-json、mlr which、describe 与 --errors-json 组成的 Agent 协作协议Miller AI 支持内部机制全解析mlr help as json、mlr which、describe 与 errors json 组成的 AgentCLI数据分析Cargo help 命令完全指南掌握 Cargo 内置帮助系统的用法与实现原理Cargo help 命令完全指南掌握 Cargo 内置帮助系统的用法与实现原理 导读 cargo help 是 CargoThe Rust package开发工具包管理器CLI构建工具Spack 内置帮助系统全解析精通 spack help 与命令行自文档化机制Spack 内置帮助系统全解析精通 spack help 与命令行自文档化机制 导读 本指南围绕 Spack 文档中的 Getting Help https:开发工具构建工具CLI上一篇终极漫画阅读体验Simple Comic如何重新定义Mac平台的数字漫画阅读下一篇10个实战案例如何用n8n工作流实现高效市场营销自动化创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价