8000 GitHub - thvitt/tomledit: Simple CLI tool to manipulate TOML files
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

thvitt/tomledit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TOMLEdit (te): Tiny CLI TOML Manipulator

TOMLEdit is a small command line tool to manipulate individual keys in a TOML file without starting an editor. If nothing else is specified, it works on pyproject.toml in the current or a parent directory.

The idea is that you pass alternating keys and values to te, and it will probably do what you want:

pyproject.toml before:

[project]
name = "tomledit"
version = "0.1.0"
authors = [{ name = "Thorsten Vitt", email = "thorsten.vitt@uni-wuerzburg.de" }]
requires-python = ">=3.13"
dependencies = ["cyclopts>=3.16.2", "tomlkit>=0.13.2"]

Command:

te project.version 0.2.0 project.readme README.md project.authors '{name = "John Doe", email = "john.doe@example.org"}'

pyproject.toml after:

[project]
name = "tomledit"
version = "0.2.0"
readme = "README.md"
authors = [{ name = "Thorsten Vitt", email = "thorsten.vitt@uni-wuerzburg.de" }, {name = "John Doe", email = "john.doe@example.org"}]
requires-python = ">=3.13"
dependencies = ["cyclopts>=3.16.2", "tomlkit>=0.13.2"]

You can also factor out the common prefix project from the command using the -p (or --prefix) option:

te -p project version 0.2.0 readme README.md authors '{name = "John Doe", email = "john.doe@example.org"}'

will have the same effect.

Use -f filename.toml to work on filename.toml instead of the nearest pyproject.toml that can be found. Use something like -F pixi.toml to find the nearest pixi.toml in the current or ancestor directory.

By default, te will automatically add to a list if it finds a list at the given key (as with the authors in the example above), and set or add the key in any other case. You can intersperse the key/value arguments with mode switch characters +, -, =, @ to modify this behaviour:

switch mode arguments description
@ auto key value ... If the key points to a list, the value is appended. Otherwise, the entry at the key is set to the value, replacing any existing value.
= set key value ... The entry at the key is set to the value, replacing any existing value.
+ add key value ... If the key points to a list, the value is appended. If the key does not exist, it is created as a list with the value. If the key exists and is not a list, it is converted to a list and the value is appended.
- remove key ... The entries at the given keys are removed. If the key points to a list, the value is removed from the list.

E.g., te -p tool.ruff fix true + extend-include "*.pyw" will set fix to true. Additionally, if the extend-include list exists, "*.pyw" will be added to it, otherwise a list will be created (due to the + mode)

About

Simple CLI tool to manipulate TOML files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0