A simple, fast, and reliable CLI utility for in-place editing of TOML files with automatic type inference and nested key support.
- π In-place editing: Modify TOML files while preserving comments and formatting
- π― Dot notation: Access nested keys with
server.database.portsyntax - π§ Smart type inference: Automatically detects booleans, integers, floats, arrays, and strings
- π Format preservation: Uses
toml_editto maintain original file structure - β‘ Fast and lightweight: Single binary with minimal dependencies
- π§ Shell-friendly: Perfect for automation and scripting
# Create or edit config.toml (default file)
echo '[database]' > config.toml
echo 'host = "localhost"' >> config.toml
echo '[app]' >> config.toml
echo '[server]' >> config.toml
# Get a value
tomler get database.host
# Set a string value
tomler set app.name "My Application"
# Set a number
tomler set server.port 8080
# Set a boolean
tomler set debug true
# Set an array
tomler set allowed_hosts "localhost,127.0.0.1,example.com"
# Work with nested keys
tomler set database.host.url "tcp://localhost:6379"# Clone the repository
git clone https://github.com/subnero1/tomler.git
cd tomler
# Build release binary
cargo build --release
# Install to ~/.cargo/bin (make sure it's in your PATH)
cargo install --path .- Rust 1.70+ (Install via rustup)
Edit TOML files in-place with simple type inference and nested keys
Usage: tomler [OPTIONS] <COMMAND>
Commands:
get Get a value by key (dot notation)
set Set a value by key (dot notation)
help Print this message or the help of the given subcommand(s)
Options:
-f, --file <FILE> TOML file path (default: config.toml) [default: config.toml]
-h, --help Print help
Retrieve a value from the TOML file using dot notation.
tomler get server.port
tomler -f app.toml get database.url
# Default prints strings with quotes
tomler get app.name # => "My Application"
# Raw string mode prints strings without quotes (useful in shells)
tomler get --raw app.name # => My Application
tomler get -r app.name # short flagSet a value in the TOML file with automatic type inference.
tomler set server.port 3000
tomler -f app.toml set debug falseTomler automatically infers the correct TOML type based on the input:
| Input | TOML Type | Example |
|---|---|---|
true, false |
Boolean | debug = true |
42, -10 |
Integer | port = 8080 |
3.14, 0.5 |
Float | timeout = 30.5 |
a,b,c |
Array | hosts = ["a", "b", "c"] |
1,2,3 |
Integer Array | ports = [80, 443, 8080] |
"hello", anything else |
String | name = "hello" |
Simple comma-separated values are converted to arrays:
# Creates: ports = [80, 443, 8080]
tomler set ports "80,443,8080"
# Creates: tags = ["web", "api", "production"]
tomler set tags "web,api,production"
# Quoted strings are treated as single values:
# Creates: description = "Hello, World!"
tomler set description "\"Hello, World!\""- Default file:
config.toml(in current directory) - Custom file: Use
-for--fileoption - File creation: Creates file if it doesn't exist (for
setoperations) - Format preservation: Maintains comments, spacing, and key order
# Initialize a new config
tomler set app.name "MyApp"
tomler set app.version "1.0.0"
tomler set app.debug false
# Configure server
tomler set server.host "0.0.0.0"
tomler set server.port 8080
tomler set server.workers 4
# Set up database
tomler set database.url "postgresql://localhost/myapp"
tomler set database.pool_size 10
tomler set database.timeout 30.0Result in config.toml:
[app]
name = "MyApp"
version = "1.0.0"
debug = false
[server]
host = "0.0.0.0"
port = 8080
workers = 4
[database]
url = "postgresql://localhost/myapp"
pool_size = 10
timeout = 30.0# Set allowed origins for CORS
tomler set cors.allowed_origins "http://localhost:3000,https://example.com"
# Set multiple environment variables
tomler set env.required "DATABASE_URL,SECRET_KEY,API_KEY"
# Set numeric arrays
tomler set monitoring.alert_thresholds "50,75,90,95"#!/bin/bash
# Read current port
current_port=$(tomler get server.port)
echo "Current port: $current_port"
# Read a string value without quotes using raw mode
app_name=$(tomler get --raw app.name)
echo "App name: $app_name"
# Update configuration based on environment
if [[ "$ENV" == "production" ]]; then
tomler set app.debug false
tomler set server.workers 8
tomler set database.pool_size 20
else
tomler set app.debug true
tomler set server.workers 2
tomler set database.pool_size 5
fi
# Set deployment timestamp
tomler set deployment.timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)"FROM rust:1.70 AS builder
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /target/release/tomler /usr/local/bin/
RUN tomler set app.environment "production"
RUN echo "Environment: $(tomler get --raw app.environment)"Tomler provides clear error messages:
# File not found
$ tomler -f missing.toml get key
Error: failed to read missing.toml: No such file or directory
# Invalid TOML syntax
$ echo "invalid toml [" > bad.toml
$ tomler -f bad.toml get key
Error: failed to parse toml file bad.toml: expected `]`, found eof
# Key not found
$ tomler get nonexistent.key
Key not found: nonexistent.keyExit codes:
0: Success1: General error (file I/O, parsing, etc.)2: Key not found (get command only)
When retrieving values with get, Tomler prints TOML tokens by default. That means strings include their quotes (e.g. "example"). If you're piping output to other commands or using shell variables, you may prefer unquoted strings.
- Use
--raw(or-r) to print strings without enclosing quotes. - Non-string values (numbers, booleans, arrays) are unaffected and print the same with or without
--raw.
Examples:
# Quoted by default
tomler get app.name # => "MyApp"
# Unquoted with --raw
tomler get --raw app.name # => MyApp
# Non-string values are unchanged
tomler get --raw server.port # => 8080
tomler get --raw debug # => truegit clone https://github.com/subnero1/tomler.git
cd tomler
# Development build
cargo build
# Release build
cargo build --release
# Run tests
cargo test
# Check formatting and linting
cargo fmt --check
cargo clippy -- -D warningstomler/
βββ src/
β βββ main.rs # CLI interface and argument parsing
β βββ lib.rs # Core TOML manipulation logic
βββ tests/
β βββ integration.rs # Integration tests
βββ Cargo.toml # Project configuration
βββ README.md # This file
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_nameContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please ensure:
- Tests pass (
cargo test) - Code is formatted (
cargo fmt) - No clippy warnings (
cargo clippy)
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with toml_edit for format-preserving TOML manipulation
- CLI powered by clap
- Error handling via anyhow
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with β€οΈ by Chinmay Pendharkar