{"id":17941864,"url":"https://github.com/ceejbot/tomato","last_synced_at":"2025-03-24T13:33:22.164Z","repository":{"id":50736750,"uuid":"519994731","full_name":"ceejbot/tomato","owner":"ceejbot","description":"🍅 A command-line tool to get and set values in toml files while preserving comments and formatting","archived":false,"fork":false,"pushed_at":"2023-09-24T22:24:13.000Z","size":104,"stargazers_count":23,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"latest","last_synced_at":"2025-03-24T00:48:26.298Z","etag":null,"topics":["cli","rust","toml"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ceejbot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-08-01T06:42:40.000Z","updated_at":"2024-12-24T00:25:53.000Z","dependencies_parsed_at":"2023-09-25T01:41:52.332Z","dependency_job_id":null,"html_url":"https://github.com/ceejbot/tomato","commit_stats":{"total_commits":41,"total_committers":1,"mean_commits":41.0,"dds":0.0,"last_synced_commit":"def64fbda5db944aade9959babbb3b8ed1c80f5c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Ftomato","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Ftomato/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Ftomato/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Ftomato/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceejbot","download_url":"https://codeload.github.com/ceejbot/tomato/tar.gz/refs/heads/latest","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245279972,"owners_count":20589555,"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","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":["cli","rust","toml"],"created_at":"2024-10-29T02:04:32.594Z","updated_at":"2025-03-24T13:33:21.865Z","avatar_url":"https://github.com/ceejbot.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# tomato\n\n[![Test the tomato](https://github.com/ceejbot/tomato/actions/workflows/test.yaml/badge.svg)](https://github.com/ceejbot/tomato/actions/workflows/test.yaml)\n![Crates.io](https://img.shields.io/crates/v/tomato-toml)\n\nGet, set, and delete values in TOML files while preserving comments and formatting.\n\nThat's it. That's the feature set. I wrote `tomato` to satisfy my own primary use\ncase, which is to read values of various types from a TOML preferences file,\nprocess those values in bash tooling, and infrequently update those values from\nother bash scripts.\n\nTo install:\n\n```shell\n# using homebrew:\nbrew tap ceejbot/tap\nbrew install tomato\n\n# if you have rust installed and prefer to build from source:\ncargo install tomato-toml\n\n# once installed:\ntomato --help\n```\n\nOr snag a pre-built executable from [the releases](https://github.com/ceejbot/tomato/releases/latest).\n\nAn alternative tool would be [dasel](https://daseldocs.tomwright.me), if you\ndon't need to preserve comments and formatting when you modify a value. `dasel`\nalso supports a large variety of file formats.\n\nIf you need to convert among JSON, YAML, and TOML, check out\n[jyt](https://github.com/ken-matsui/jyt).\n\n## Usage\n\nThe short version:\n\n* Get a key: `tomato get \u003cdotted.key\u003e \u003cfile\u003e`\n* Set a key: `tomato set \u003cdotted.key\u003e \u003cvalue\u003e \u003cfile\u003e`\n* Delete a key: `tomato rm \u003cdotted.key\u003e \u003cfile\u003e` (with lots of aliases for `rm`)\n\nThe `set` and `rm` subcommands modify the input file in place. Thanks to the magic of\n[toml_edit](https://lib.rs/crates/toml_edit), they do so without disturbing whitespace\nand comments.\n\nBy default tomato emits data a form suitable for immediate use in bash scripts.\nStrings are unquoted, for instance. The `bash` format generates output suitable\nfor `eval` inside bash. Use this for arrays and associative arrays. If you need\nto consume more complex output, you might select `json` format and pipe the\nresults to `jq`. And of course if you need TOML, use `toml`.\n\nThe longer version:\n\n```text\n🍅 tomato 0.2.0\nA command-line tool to get and set values in toml files while preserving comments and formatting.\n\nKeys are written using `.` to separate path segments. You can use `array[idx]` syntax to index into\narrays if you want to. For example, to get the name of the current crate you're working on, you'd\nrun `tomato get Cargo.toml package.name`.\n\nBy default tomato emits data in a form suitable for immediate use in bash scripts if they are\nprimitive values: strings are unquoted, for instance. If you want to use more complex data types,\nconsider one of the other output formats.\n\nTo read from stdin instead of a file, omit the file from the arguments. Operating on stdin changes\nthe behavior of set and rm somewhat, under the assumption that you are using this tool in a shell\nscript. If you read from stdin, normal output (the old value) is suppressed. Instead the modified\nfile is written to stdout in json if you requested json, toml otherwise. The 'bash' format option is\nignored.\n\nUSAGE:\n\ttomato [OPTIONS] \u003cSUBCOMMAND\u003e\n\nOPTIONS:\n\t-b, --backup\n\t\t\tBack up the file to \u003cfilepath\u003e.bak if we write a new version. This option is ignored\n\t\t\twhen we're operating on stdin\n\n\t-f, --format \u003cFORMAT\u003e\n\t\t\tHow to format the output: json, toml, bash, or raw\n\t\t\t[default: raw]\n\n\t-h, --help\n\t\t\tPrint help information\n\n\t-V, --version\n\t\t\tPrint version information\n\nSUBCOMMANDS:\n\tget     Get the value of a key from the given file\n\tset     Set a key to the given value, returning the previous value if one existed\n\trm      Delete a key from the given file, returning the previous value if one existed\n\tcompletions\n\t\t\tGenerate completions for the named shell\n\thelp    Print this message or the help of the given subcommand(s)\n```\n\n`get` and `rm` both print empty string to stdout if the target key is not found. `set`\nexits with a non-zero status with a message printed to stderr if the target key is not found.\n\n## Setting booleans and numbers\n\nTomato treats booleans and numbers slightly differently than ordinary values in its `set` command. It's likely that you'll need to set both true-the-boolean and \"true\"-the-string as values at some point. To distinguish `true` the boolean from `\"true\"` the string on the command line, use quotes around the string and do not use them around the boolean. Remember that your shell strips the first layer of quoting, so you need to use two layers! That is, use `'\"true\"'` to get a string, and `true` to get a boolean.\n\nHere are examples that work with the test fixture:\n\n```terminal\n# set a value to a boolean\n➜ tomato -f toml set testcases.are_complete true fixtures/sample.toml\nfalse\n➜ tomato -f toml get testcases.are_complete fixtures/sample.toml\ntrue\n# set a value to a string\n➜ tomato -f toml set testcases.are_complete '\"false\"' fixtures/sample.toml\ntrue\n# set a value to a number\n➜ tomato -f toml set testcases.are_complete 20 fixtures/sample.toml\n\"false\"\n# set a value to a string that happens to be a number\n➜ tomato -f toml set testcases.are_complete \"'20'\" fixtures/sample.toml\n20\n➜ tomato -f toml get testcases.are_complete fixtures/sample.toml\n\"20\"\n```\n\n## Examples\n\nHere are some examples run against the Cargo manifest for this project:\n\n```shell\n$ tomato get package.name Cargo.toml\ntomato\n$ tomato --format json get package.name Cargo.toml\n\"tomato\"\n$ cat Cargo.toml | tomato get package.name\ntomato\n\n# set examples\n$ tomato set package.name broccoli Cargo.toml\ntomato\n$ tomato set package.keywords[1] yaml Cargo.toml\ntoml\n\n# Keys that don't exist\n$ tomato get dependencies.toml_edit[0] Cargo.toml\n\n$ tomato set dependencies.toml_edit[0] \"first!\" Cargo.toml\nError: unable to index into non-array at dependencies.toml_edit.0\n\n# rm has a number of aliases to prevent user frustration\n$ tomato --format json del package.categories[0] Cargo.toml\n\"command-line-utilities\"\n```\n\nLook at the `examples/` directory for some sample bash scripts with more varied examples,\nincluding examples of using lists and associative arrays in bash.\n\n## CONTRIBUTING\n\nHeck, yeah! Please keep the major use case in mind: you need to read toml and do stuff\nwith it in bash. I'm happy to accept anything that improves that use case or makes the Rust\nparts better.\n\n## LICENSE\n\n[Blue Oak Model License](https://blueoakcouncil.org/license/1.0.0); text in [LICENSE.md](./LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceejbot%2Ftomato","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceejbot%2Ftomato","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceejbot%2Ftomato/lists"}