Skip to content

Feature: Ability to append to array if not exist #4

@tgrushka

Description

@tgrushka

Hi, thank you for this crate.

It's appalling we all now have to use TOML (a Toxic Oligarchic Mechanistic Lock-in) just like JavaScript. Try scripting edits. See? "Designed to be written by humans." Config formats should never impose this limitation! You can't even wrap lines! Some people love that complexity, but your tool makes it more bearable for me. I want to use my brain for programming in Rust, not for editing config files and 1970s bash scripts!

direnv is the straw that broke the camel's back. Have to grant it permission on every folder over and over. Not anymore.

cringeworthy justfile:

setup-direnv:
    # ...
    echo "Setting up direnv config..."
    PREFIX="$HOME/apps"
    tomato -f toml set global.load_dotenv true $CONFIG_FILE

    # monstrosity that should not exist: add value if not exists
    existing=$(tomato get whitelist.prefix $CONFIG_FILE)
    if [ -n "$existing" ]; then
        echo "looking for $PREFIX..."
        while IFS= read -r path; do
            echo "path: $path"
            if [[ "$path" == "$PREFIX" ]]; then
                exit 0
            fi
        done <<< "$existing"
        echo "Existing whitelist.prefix missing PREFIX: $existing"
    else
        echo "No existing whitelist.prefix found, setting up..."
    fi

    tomato -f toml append whitelist.prefix "$PREFIX" $CONFIG_FILE

Would be wonderful to replace with:

better justfile:

setup-direnv:
    # ...
    echo "Setting up direnv config..."
    PREFIX="$HOME/apps"
    tomato -f toml set global.load_dotenv true $CONFIG_FILE
    tomato -f toml append --unique whitelist.prefix "$PREFIX" $CONFIG_FILE

Is it achievable?

Again, thanks. I could just write a string, but multiline strings in justfiles are awful. I wanted an idiomatic, rust-like solution. You've provided it, it's 90% there.

P.S. Why isn't tomato a standard Cargo tool? We're all forced to use TOML, so why don't the rustlang maintainers provide a built-in tool since it's required? We have to use it, no choice. All the abandoned tq utils on crates.io are telling of a need.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions