#env-var #variables #command-line-tool #replace #utility #cli

bin+lib repvar

A tiny CLI tool that replaces variables of the style ${KEY} in text with their respective value. It can also be used as a rust library

10 releases

0.13.2 Jun 1, 2024
0.13.1 Dec 4, 2023
0.13.0 Nov 28, 2023
0.1.17 Aug 8, 2021

#487 in Text processing

Download history 3/week @ 2024-07-19 5/week @ 2024-07-26 14/week @ 2024-09-20 9/week @ 2024-09-27 2/week @ 2024-10-04

680 downloads per month
Used in 3 crates (2 directly)

AGPL-3.0-or-later

52KB
806 lines

repvar - Variable replacing, UNIX-style text filter

License: AGPL-3.0-or-later REUSE status Repo Package Releases Documentation Releases Dependency Status Build Status

In cooperation with FabCity Hamburg In cooperation with Open Source Ecology Germany

A tiny CLI tool that replaces variables of the style ${KEY} in text with their respective value. It can also be used as a rust library.

For the CLI tool, the variables can be read from the environment or be directly supplied through CLI switches, like -Dkey=value.

NOTE
The author is a rust-newb. This crate probably only makes sense for himself, and it is not using the power of rust as should be. It also could probably be written in just 10 lines of code, using one or two regexes, not loosing any performance.

Usage

Simplisitc

$ export KEY_A="replacement"   # setting an env.-variable
$ echo 'Text ${KEY_A}.' \      # input text
    | repvar --env             # replacing variables
Text replacement.              # output

Slightly more elaborate

$ export first="the environment"
$ echo 'Variables from ${first}, ${second}, ${not_supplied} and $${quoted}.' \
    | repvars --env -D"second=the CLI"
Variables from the environment, the CLI, ${not_supplied} and ${quoted}.

More usage info can be seen when running:

repvars --help

Building

# To get a binary for your system
cargo build --release

# To get a 64bit binary that is portabel to all Linux systems
scripts/build

Testing

To run unit-, doc- and integration-tests:

scripts/test

Similar projects

Funding

This project was funded by the European Regional Development Fund (ERDF) in the context of the INTERFACER Project, from August 2021 (project start) until March 2023.

Logo of the EU ERDF program

Dependencies

~4–6MB
~100K SLoC