{"id":13493075,"url":"https://github.com/2moe/tomlyre","last_synced_at":"2025-08-20T00:04:13.300Z","repository":{"id":154409708,"uuid":"632099681","full_name":"2moe/tomlyre","owner":"2moe","description":"📁💻🔍🔧 This CLI utility facilitates effortless manipulation and exploration of TOML, YAML, JSON and RON files.","archived":false,"fork":false,"pushed_at":"2024-05-03T13:38:42.000Z","size":5680,"stargazers_count":23,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-04-02T15:03:40.330Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2moe.png","metadata":{"files":{"readme":"Readme-zh.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-24T17:54:50.000Z","updated_at":"2025-03-02T05:06:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"cd77257d-a9b2-42ff-ab57-eb7ee4646ce5","html_url":"https://github.com/2moe/tomlyre","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/2moe/tomlyre","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Ftomlyre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Ftomlyre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Ftomlyre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Ftomlyre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2moe","download_url":"https://codeload.github.com/2moe/tomlyre/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Ftomlyre/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271242036,"owners_count":24724978,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:11.946Z","updated_at":"2025-08-20T00:04:13.254Z","avatar_url":"https://github.com/2moe.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# TomLyre\n\n一款用于处理配置文件的小工具。\n\n您可以用它来自由探索 toml、yaml、json、ron、bson、Lisp S-exp 以及 xml，并从中发现乐趣。\n\n\u003e 默认情况下，没有启用 bson 和 xml 功能。\n\n## 安装\n\n![latest-map](https://raw.githubusercontent.com/2moe/tomlyre/assets/assets/img/svg/latest.svg)\n\n先单击打开 svg 图片，然后对蓝色高亮的超链接处（例如 “arm64.deb”）按下鼠标中键。  \n如果没有鼠标的话，可以长按触摸屏，手动选择“在新标签页中打开”，这样子就可以下载了。\n\n上面那张 svg 会自动更新，如果因为浏览器缓存而导致无法获取最新的 svg，则请前往 releases 获取固定版本的 svg。\n\n### ubuntu\n\n对于 **ubuntu**，我们可以直接用 `apt install [deb文件的路径]` 来安装。\n\n\u003e 如果没有 root 权限，则需要用 `sudo` 或 `doas` 之类的提权命令。\n\n假设 deb 文件的路径为 `/app.deb`, 那么安装命令就是 `apt install /app.deb`\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/svg/logo/ubuntu.svg\" alt=\"ubuntu\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/en/apt_install_deb-file.png\" alt=\"apt install deb\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### alpine\n\n让我们来试试 alpine 能不能安装 deb 吧！\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/svg/logo/alpine.svg\" alt=\"alpine\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/en/alpine-riscv64.png\" alt=\"alpine rv64 container\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n它是 `musl-linux-riscv64`，而不是 `riscv64`, 看起来好像不能安装的样子咦？\n\n让我们来强制安装看看。\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/svg/logo/alpine.svg\" alt=\"alpine\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/en/alpine-dpkg-i.png\" alt=\"alpine \u0026 dpkg\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003e Q: 喔哦! 真是太不可思议了！为什么它不仅可以装上去，而且还能跑呢？\n\nA: 因为它是静态编译的。\n\n\u003e 有时候 glibc 的静态链接可能会出问题，建议用 musl。\n\n考虑到不同发行版的包管理器可能会冲突，因此建议在 alpine 上使用 alpine 自家的 `apk`， 而不是 debian 的 `dpkg`。\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/svg/logo/alpine.svg\" alt=\"alpine\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/en/alpine_dpkg-X.png\" alt=\"alpine \u0026 dpkg\"\u003e您可以把它拆出来用\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### wasm\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/svg/logo/wasm.svg\" alt=\"wasm\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/en/wasmtime-run-tomlyre.png\" alt=\"alpine \u0026 dpkg\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n下载完 `wasm.zst` 文件后，需要将其解压出来。\n\n接着需要获取 runtime，然后让 runtime 来加载这个 wasm 文件。\n\n比方说，您可以用 `wasmer`:\n\n```sh\nwasmer --dir . --env LANG=zh ./tomlyre.wasm\n```\n\n也可以用 `wasmtime`:\n\n```sh\nwasmtime --dir . --env LANG=zh ./tomlyre.wasm\n```\n\n或者是其他您喜欢的 runtimes。\n\n### CI\n\n您如果需要在 Linux x64 的 CI 环境中使用它，则可使用以下命令\n\n```sh\ndocker run -it --rm \\\n  -u $(id -u) \\\n  -v $PWD:/local \\\n  -w /data \\\n  ghcr.io/2moe/tomlyre:x86_64-unknown-linux-musl \\\n  cp tomlyre /local\n```\n\n这相当于把容器内部的 `/data/tomlyre` 复制到当前目录\n\n### 其他\n\n对于以 `tar.xz`/`tar.bz2` 为后缀的文件，我们可以使用 `tar -xvf [压缩包]` 来解压。\n\n```sh\ntar -xvf x64.tar.xz\n```\n\n解压完成后，在终端里调用 `./tomlyre` 即可。\n\n## 功能\n\n核心功能只有三个：\n\n- 转换 (conv)\n- 获取 (get)\n- 设置/修改 (set)\n\n除此之外，全都是额外的功能，例如设置主题与表格的样式。\n\n使用 `--help` 能获取详细的帮助信息。\n\n- `tomlyre set` 相当于 `tomlyre set -h` ，它会输出简洁的帮助信息。\n- `tomlyre set --help` 会输出非常详细的信息。\n- 同理，其他子命令也能调用 `--help`。\n\n\u003c!-- ![set--help](assets/img/zh/set_help.jpg) --\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/zh/set_help.jpg\" alt=\"set_help\"\u003e\u003cp align=\"center\"\u003e\u003ccode\u003eset --help\u003c/code\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img/zh/conv_help.jpg\" alt=\"conv_help\"\u003e\u003cp align=\"center\"\u003e\u003ccode\u003econv --help\u003c/code\u003e\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### 主题\n\n使用 `--theme` 参数 (可以简写为 `-t`) 来指定主题，例如 `tomlyre -t \"One Dark\" conv test.yml -t json`。\n\n\u003e `conv` 子命令的 `-t` 指的是 `--to`，而根命令的 `-t` 则是 `--theme`。\n\n当未指定主题名称时，会列举出所有的主题。\n\n以下是内置的主题，您可以手动载入主题集合包，并指定名称，而不是使用内置的主题。\n\n\u003e 这些主题大都使用 MIT License，您可以在 [hlight/dev/assets/theme](https://github.com/2moe/hlight/tree/dev/assets) 里找到内置主题以及相关的许可证文件。\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/dracula.png\" alt=\"dracula\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/monokai-bright.png\" alt=\"monokai-bright\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n      \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/monokai.png\" alt=\"monokai\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/monokai-light.png\" alt=\"monokai-light\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n      \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/onedark.png\" alt=\"onedark\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/one-dark-tomorrow.png\" alt=\"one-dark-tomorrow\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n      \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/one-half-dark.png\" alt=\"one-half-dark\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/one-half-light.png\" alt=\"one-half-light\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/widget-one-dark.png\" alt=\"widget-one-dark\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/ayu-light.png\" alt=\"ayu-light.png\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/ayu-dark.png\" alt=\"ayu-dark\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"assets/img-branch/theme/ayu-migrage.png\" alt=\"ayu-migrage\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### 表格样式\n\n使用 `--table-style` 来指定表格样式(可以简写为 `--ts`)，例如: `--table-style markdown` 或 `--ts md` 可以指定表格样式为 markdown。\n\n```sh\ntomlyre --ts md get Cargo.toml -k profile.fat\n```\n\n| profile.fat | 类型 | Value |\n| ----------- | ---- | ----- |\n| inherits    | str  | thin  |\n| lto         | str  | fat   |\n| opt-level   | str  | z     |\n\n以下为内置的表格样式：\n（非等宽字体可能会出现排版异常的问题）\n\n```plaintext\n\nstyle: default\n\n╭─────────┬──────────┬────────────╮\n│ Version ┆ Codename ┆ Created    │\n├─────────┼──────────┼────────────┤\n│ 10      ┆ Buster   ┆ 2017-06-17 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 11      ┆ Bullseye ┆ 2019-07-16 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 12      ┆ Bookworm ┆ 2021-08-14 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 13      ┆ Trixie   ┆ 2023       │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 14      ┆ Forky    ┆ 2025       │\n╰─────────┴──────────┴────────────╯\n\n\nstyle: nothing\n\n Version  Codename  Created\n 10       Buster    2017-06-17\n 11       Bullseye  2019-07-16\n 12       Bookworm  2021-08-14\n 13       Trixie    2023\n 14       Forky     2025\n\n\nstyle: ascii\n\n+---------+----------+------------+\n| Version | Codename | Created    |\n+=================================+\n| 10      | Buster   | 2017-06-17 |\n|---------+----------+------------|\n| 11      | Bullseye | 2019-07-16 |\n|---------+----------+------------|\n| 12      | Bookworm | 2021-08-14 |\n|---------+----------+------------|\n| 13      | Trixie   | 2023       |\n|---------+----------+------------|\n| 14      | Forky    | 2025       |\n+---------+----------+------------+\n\n\nstyle: ascii-borders\n\n+---------------------------------+\n| Version   Codename   Created    |\n+=================================+\n| 10        Buster     2017-06-17 |\n| 11        Bullseye   2019-07-16 |\n| 12        Bookworm   2021-08-14 |\n| 13        Trixie     2023       |\n| 14        Forky      2025       |\n+---------------------------------+\n\n\nstyle: right-u8-fat\n\n┌─────────┬──────────┬────────────┐\n│ Version │ Codename │ Created    │\n╞═════════╪══════════╪════════════╡\n│ 10      │ Buster   │ 2017-06-17 │\n├─────────┼──────────┼────────────┤\n│ 11      │ Bullseye │ 2019-07-16 │\n├─────────┼──────────┼────────────┤\n│ 12      │ Bookworm │ 2021-08-14 │\n├─────────┼──────────┼────────────┤\n│ 13      │ Trixie   │ 2023       │\n├─────────┼──────────┼────────────┤\n│ 14      │ Forky    │ 2025       │\n└─────────┴──────────┴────────────┘\n\n\nstyle: right-u8\n\n┌─────────┬──────────┬────────────┐\n│ Version │ Codename │ Created    │\n├─────────┼──────────┼────────────┤\n│ 10      │ Buster   │ 2017-06-17 │\n├─────────┼──────────┼────────────┤\n│ 11      │ Bullseye │ 2019-07-16 │\n├─────────┼──────────┼────────────┤\n│ 12      │ Bookworm │ 2021-08-14 │\n├─────────┼──────────┼────────────┤\n│ 13      │ Trixie   │ 2023       │\n├─────────┼──────────┼────────────┤\n│ 14      │ Forky    │ 2025       │\n└─────────┴──────────┴────────────┘\n\n\nstyle: right-u8-thin\n\n┌─────────┬──────────┬────────────┐\n│ Version ┆ Codename ┆ Created    │\n├─────────┼──────────┼────────────┤\n│ 10      ┆ Buster   ┆ 2017-06-17 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 11      ┆ Bullseye ┆ 2019-07-16 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 12      ┆ Bookworm ┆ 2021-08-14 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 13      ┆ Trixie   ┆ 2023       │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 14      ┆ Forky    ┆ 2025       │\n└─────────┴──────────┴────────────┘\n\n\nstyle: u8\n\n┌─────────┬──────────┬────────────┐\n│ Version ┆ Codename ┆ Created    │\n╞═════════╪══════════╪════════════╡\n│ 10      ┆ Buster   ┆ 2017-06-17 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 11      ┆ Bullseye ┆ 2019-07-16 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 12      ┆ Bookworm ┆ 2021-08-14 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 13      ┆ Trixie   ┆ 2023       │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 14      ┆ Forky    ┆ 2025       │\n└─────────┴──────────┴────────────┘\n\n\nstyle: u8-no-dividers\n\n┌─────────┬──────────┬────────────┐\n│ Version ┆ Codename ┆ Created    │\n╞═════════╪══════════╪════════════╡\n│ 10      ┆ Buster   ┆ 2017-06-17 │\n│ 11      ┆ Bullseye ┆ 2019-07-16 │\n│ 12      ┆ Bookworm ┆ 2021-08-14 │\n│ 13      ┆ Trixie   ┆ 2023       │\n│ 14      ┆ Forky    ┆ 2025       │\n└─────────┴──────────┴────────────┘\n\n\nstyle: u8-borders\n\n┌─────────────────────────────────┐\n│ Version   Codename   Created    │\n╞═════════════════════════════════╡\n│ 10        Buster     2017-06-17 │\n│ 11        Bullseye   2019-07-16 │\n│ 12        Bookworm   2021-08-14 │\n│ 13        Trixie     2023       │\n│ 14        Forky      2025       │\n└─────────────────────────────────┘\n\n\nstyle: u8-no-borders\n\n Version ┆ Codename ┆ Created\n═════════╪══════════╪════════════\n 10      ┆ Buster   ┆ 2017-06-17\n╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌\n 11      ┆ Bullseye ┆ 2019-07-16\n╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌\n 12      ┆ Bookworm ┆ 2021-08-14\n╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌\n 13      ┆ Trixie   ┆ 2023\n╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌\n 14      ┆ Forky    ┆ 2025\n\n\nstyle: horizontal\n\n---------------------------------\n Version   Codename   Created\n=================================\n 10        Buster     2017-06-17\n---------------------------------\n 11        Bullseye   2019-07-16\n---------------------------------\n 12        Bookworm   2021-08-14\n---------------------------------\n 13        Trixie     2023\n---------------------------------\n 14        Forky      2025\n---------------------------------\n\n\nstyle: round-u8\n\n╭─────────┬──────────┬────────────╮\n│ Version │ Codename │ Created    │\n├─────────┼──────────┼────────────┤\n│ 10      │ Buster   │ 2017-06-17 │\n├─────────┼──────────┼────────────┤\n│ 11      │ Bullseye │ 2019-07-16 │\n├─────────┼──────────┼────────────┤\n│ 12      │ Bookworm │ 2021-08-14 │\n├─────────┼──────────┼────────────┤\n│ 13      │ Trixie   │ 2023       │\n├─────────┼──────────┼────────────┤\n│ 14      │ Forky    │ 2025       │\n╰─────────┴──────────┴────────────╯\n\n\nstyle: round-u8-fat\n\n╭─────────┬──────────┬────────────╮\n│ Version ┆ Codename ┆ Created    │\n╞═════════╪══════════╪════════════╡\n│ 10      ┆ Buster   ┆ 2017-06-17 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 11      ┆ Bullseye ┆ 2019-07-16 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 12      ┆ Bookworm ┆ 2021-08-14 │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 13      ┆ Trixie   ┆ 2023       │\n├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ 14      ┆ Forky    ┆ 2025       │\n╰─────────┴──────────┴────────────╯\n\n\nstyle: markdown\n\n| Version | Codename | Created    |\n|---------|----------|------------|\n| 10      | Buster   | 2017-06-17 |\n| 11      | Bullseye | 2019-07-16 |\n| 12      | Bookworm | 2021-08-14 |\n| 13      | Trixie   | 2023       |\n| 14      | Forky    | 2025       |\n```\n\n### conv\n\n警告：如果两种配置之间的数据类型不能完全兼容，那么转换后数据类型会发生改变。\n\n---\n\n比如说 ron 有 char 类型，代表单个字符。\n\n以 `hello，世界` 为例 ，这是一个 string。  \n'h' 是 char, \"h\" 是 string。  \n\"世界\" 是 string, '世' 是 char。\n\n然而，`json 1.0` 和 `toml 1.0` 都没有 char 类型。\n\nhello.ron:\n\n```ron\n{\n   \"s\": '世',\n   \"j\": '界',\n}\n```\n\n```sh\ntomlyre c hello.ron -t json\n```\n\njson:\n\n```json\n{\n  \"j\": \"界\",\n  \"s\": \"世\"\n}\n```\n\n因此，`ron` 的 char 转成 `json 1.0` 会变成 string。\n\n---\n\n再比如， 目前有很多种配置格式都支持这两种特殊的浮点数：**NaN** 和 **inf**，但 `json 1.0` 不支持。\n在 `json 1.0` 中，它们都会变成 `null`。\n\nf64-map.toml:\n\n```toml\n[double-float-map]\nnot-a-num = nan\ninfinity = inf\n```\n\n```sh\ntomlyre conv f64-map.toml -t ./f.yaml --save\n```\n\nf.yaml:\n\n```yaml\ndouble-float-map:\n  infinity: .inf\n  not-a-num: .nan\n```\n\n```sh\ntomlyre conv f.yaml -t ron --sv\n```\n\nf.ron:\n\n```ron\n{\n    \"double-float-map\": {\n        \"infinity\": inf,\n        \"not-a-num\": NaN,\n    },\n}\n```\n\n```sh\ntomlyre conv f.ron -t sexp\n```\n\n\u003e sexp 指的是 Lisp S-Expressions\n\n```lisp\n((\"double-float-map\" (\"infinity\" . inf) (\"not-a-num\" . NaN)))\n```\n\n```sh\ntomlyre conv f.ron -t json\n```\n\n```json\n{\n  \"double-float-map\": {\n    \"infinity\": null,\n    \"not-a-num\": null\n  }\n}\n```\n\n```sh\ntomlyre conv f.ron -t json5\n```\n\n```json5\n{ \"double-float-map\": { infinity: Infinity, \"not-a-num\": NaN } }\n```\n\n---\n\nQ： `json` 有，但其他格式没有的数据类型是什么？\n\nA: `null`\n\n比如说：`toml 1.0` 和 `ron` 都不支持 `null` 值，如果将包含 `null` 的 `json 1.0` 进行转换，`toml` 会直接报错，而 `ron` 则会将其转换成空元组 `()`, 也就是俗称的单元类型（**Unit**）。\n\n\u003e 注： ron 使用的是 `Option\u003cT\u003e` 类型, 值为 `Some(T)` 或 `None`，而不是 `null`。\n\n此外，不同的配置格式之间还有不少的区别，我们并没有全部列举出来。\n\n### get 与 set\n\n当用 `set` 子命令指定了 key, 并且未指定 value 时，相当于更详细版本的 `set`。\n\n比如说，我们使用以下命令从 stdin 中读取并解析数据\n\n\u003e get 后面的 `-` 代表来源是 stdin，而不是具体的文件\n\n```sh\ncurl -sL https://raw.githubusercontent.com/2moe/tomlyre/main/Cargo.toml | tomlyre get -  -k profile.thin.strip\n```\n\n当使用 `get` 时，stdout 会输出 `true`。\n\n而当我们把 `get` 改成 `set` 时, 它会输出 ：\n\n```yaml\ntrue\n\nkey:    [\"profile\", \"thin\", \"strip\"]\ntype:   boolean\nvalue:\n true\n```\n\n\u003e Q: 输出的信息是越多越好吗？\n\nA: 不是的！  \n这主要取决于我们的使用目的。  \n当我们需要用脚本来获取具体的值时，只需要有效的信息，多余的信息不仅无用，而且还会干扰数据的获取。  \n与之相反，当我们需要手动修改时，有具体的信息往往会更好。\n\n### set\n\n我们可以对 `set`子命令使用 `--help` 来获取详细信息。\n\n基本用法为： `set [来源文件] -k [用\".\"来分割的keys] [指定数据类型的选项] [指定数据类型的值(可能为空，也可能有多个)]`\n\n例如 `set test.toml --key package.edition --str 2024`\n\n---\n\n\u003e 注意：  \n\u003e 只有当 src 的格式为 toml 时才会保留注释，其他格式不会。  \n\u003e 其他格式会先转换成 toml 再进行修改，转换后的文件不会保留注释。\n\n---\n\n此处只是简单地列举一下它支持的数据类型。\n\n基本数据类型\n\n| 选项       | 别名           | 值的类型            | 描述                      | 示例                        |\n| ---------- | -------------- | ------------------- | ------------------------- | --------------------------- |\n| -s         | --str          | String              | 字符串类型                | `-s \"1.114.5-beta.1\"`       |\n| -b         | --bool         | bool                | 布尔类型                  | `-b true`                   |\n| --f64      |                | f64                 | 双精度浮点数类型          | `--f64 314e-2`              |\n| -n         | --num/--int    | i64                 | 64 位有符号整数类型       | `-n 2048`                   |\n| -a         | --arr          | `Vec\u003cString\u003e`       | 字符串的数组              | `-a hello -a world`         |\n| --num-arr  | --na           | `Vec\u003ci64\u003e`          | i64 的数组                | `--na 11 --na -3`           |\n| --f64-arr  | --fa           | `Vec\u003cf64\u003e`          | f64 的数组                | `--fa 3.14 --fa 2.71828182` |\n| --bool-arr | --ba           | `Vec\u003cbool\u003e`         | bool 的数组               | `--ba true --ba false`      |\n| -i         | --inline-table | `Vec\u003c(key, value)\u003e` | 内联表                    | `-i name sd -i os android`  |\n| --rm       |                |                     | 删掉指定的 key 及其 value |                             |\n\n此外，还有一些不那么“基本”的数据类型。比如“标准表”，“表数组”，以及 DateTime。\n\n标准表和内联表很像，如果不知道用哪个，那就用 `-i`, 而不是用 `-m`。  \n对于 **toml** 以外的格式，创建新表时，请一律使用 `-i`, 而不是 `-m`！\n\n假设 hello.toml 里面有个名为 test 的表数组，索引为 0 的 map 有个 key 叫 **kk**, 其值为 **v**。\n\n```toml\n[[test]]\nkk = \"v\"\n```\n\n```sh\nset hello.toml -k test.\n```\n\n| test. | 类型 | Value |\n| ----- | ---- | ----- |\n| 0.kk  | str  | v     |\n\n```yaml\nkey:    [\"test\"]\ntype:   array of tables\nvalue:\n[{ kk = \"v\" }]\n```\n\n让我们用 `-m` 或 `--table` 来创建一个子表看看。\n\n```sh\nset hello.toml --key test.0.a --map hello world --pre\n```\n\n输出内容:\n\n```yaml\nkey: [\"test\", \"0\", \"a\"]\ntype: table\nnew value: hello = \"world\"\n```\n\n| test.0  | 类型 | 新值(value) |\n| ------- | ---- | ----------- |\n| kk      | str  | v           |\n| a.hello | str  | world       |\n\n```toml\n[[test]]\nkk = \"v\"\n\n[test.a]\nhello = \"world\"\n```\n\n看起来好像没问题，再用内联表试试。\n\n```sh\nset hello.toml -k test.0.a -i hello world --pre\n```\n\n输出内容:\n\n```toml\n[[test]]\nkk = \"v\"\na = { hello = \"world\" }\n```\n\n对于这种情况，标准表与内联表是一样的。（虽然看起来不一样，但是其解析的结果是一样的。）\n\n可是当 key 为 `test.0.x.y.z` 时，里面有多个不存在的嵌套子表，您可以尝试分别用`-m` 与 `-i`。\n\n在亲自尝试之后，我相信您定能知晓不使用 `-m` 的缘由。\n\n## 日志级别\n\n详细程度从高到低，依次是 `trace` \u003e `debug` \u003e `info` \u003e `warn` \u003e `error`\n\n其中 `trace` 是最详细的。\n\n默认的级别为 `info`。\n\n我们可以通过设置环境变量来修改日志级别\n\n\u003e v0.0.1-beta.1 及其之前的版本使用 `RUST_LOG` 环境变量， 而不是 `TOMLYRE_LOG`\n\n```sh\nenv TOMLYRE_LOG=debug tomlyre\n```\n\n## 题外话\n\n### 设计初衷\n\n\u003e Q: 这个工具的设计初衷是什么？\n\nA:\n初衷是让大家在 CLI 里，能以一种简单和优雅的方式去查询与修改配置文件。\n\n大概在一两年前的时候，我曾在另一个项目的文档中说过：\n\n- 那个项目之后会用 `toml` 格式进行配置\n  - 并且还介绍了一些具体的细节\n    - 比如用 `get` 子命令来获取\n    - 用 `set` 来修改\n\n在设计时，我一直在纠结，我到底该用 toml、yaml 还是 ron，或者是做的更绝一点，直接用数据库呢？\n\n起初的时候，我已经写完了同时支持 toml 与 yaml 的代码。  \n这涉及到了解析优先顺序的问题。  \n当同时存在以下文件时，程序应该先解析哪一个呢？\n\n- cfg.toml\n- cfg.Toml\n- cfg.yaml\n- cfg.yml\n- cfg.YAML\n- cfg.YML\n- cfg.Yaml\n\n这时候就要有核心配置了，通过核心配置来指定用户配置。  \n那么问题来了，核心配置是什么格式呢？  \n我们可以环境变量来指定核心配置的格式。\n\n这么看来貌似不是很难呀！\n\n请注意：不同格式有着不同的规范，兼容不同格式得要了解它们之间的差异。  \n如果要支持更多的格式，那么会变得有点麻烦。\n\n有些事情本身不是很难，但是需要花很多时间和精力去处理。\n\n最终，我把它分离成单独的小工具。\n\n这样子，大家可以通过这个小工具来间接支持多种格式。（我们看到的是 yaml, 但是实际修改的是 toml 文件）\n\n### yaml\n\n\u003e Q: 为什么要支持多种配置格式呢？大家都说 `yaml` 的可读性好，只支持 yaml 不行吗？\n\n虽然我很想坚定地回答：“不行！”，但实际上这取决于您以及您的用户的需求。\n\n**yaml** 支持比 **toml** 和 **json** 更高级的功能，如 `引用`, `包含` 和 `标签` 等。\n\n1. 锚点(anchor)和别名(alias): 允许在同一文档中复用相同的数据结构或节点。\n   Anchor and Alias: Allows reusing the same data structure or node within the same document.\n\n2. 引用(References): 允许在 **YAML** 文档中引用其他节点的值。\n   References: Allows referencing values from other nodes within a YAML document.\n\n3. 自定义标签(Custom Tags): 允许定义自己的标签，更好地控制 **YAML** 数据类型的解析。\n   Custom Tags: Allows defining custom tags to better control the parsing of YAML data types.\n\n4. 包含(Includes): 允许将多个 **YAML** 文件组合成一个文件，提高可重用性（复用性）。\n   Includes: Allows combining multiple YAML files into one file, improving code reusability\n\n您如果需要这些功能，那么使用 **yaml** 是一个极佳的选择。\n\n您如果不需要这些功能，那么选择 yaml 是否值得呢？\n\n这个问题值得探讨。\n\n\u003e 正方观点：功能越多越好，我可以不用，但是你不能没有。\n\u003e\n\u003e 反方观点：太多功能会增加复杂度和混乱度。\n\n除了可读性和功能的权衡外，还要考虑普通用户的感受。\n\n\u003e 如果一个配置文件包含了复杂的嵌套结构，并且您的用户没有一个 “高级” 的编辑器，那么 yaml 的缩进特性可能很容易导致编写出错。\n\n如果您的用户可能会在早期 Windows 的 notepad(记事本) 上编写配置，那么使用 **toml** 会不会比 **yaml** 更好呢？\n\n\u003e 早期指的是 2022 年以前的 Windows 10，那时候的 notepad 只有最基本的功能。  \n\u003e Windows 的工具在不断发展，也许有一天，notepad 也有语法高亮，空白字符显示和代码补全等高级功能。因此我将其限定为“早期”。\n\n用 Windows 可能不太恰当，因为 Windows 上的编辑器软件非常丰富。  \n就算你在大街上随便找个小孩子，他都能帮你轻松搞定编辑器软件的安装。\n\n于是，我们把问题变成了：“您好，我的环境是 riscv64 架构，uClibc 的 Linux, 没有包管理器，请问您能否在您的电脑上帮我配置交叉编译环境？再编译一个超轻量级的编辑器，需要有语法高亮，并且能对空白字符进行高亮显示。”\n\nemmm，还是不要太为难那个小朋友了。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2moe%2Ftomlyre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2moe%2Ftomlyre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2moe%2Ftomlyre/lists"}