Easily replace variables within file contents and filenames!
Project description
JSON Variable Replacer CLI (repvar)
This project is a Command Line Interface (CLI) application built using Python and the typer library. It allows you to replace variables in files and filenames within an input folder and save the processed files to an output folder.
Features
- Variable Replacement: Replace variables in the format
${variable}found in file contents and filenames. - Transformations: Supports variable transformations such as:
lowercase: Convert variable value to lowercase.uppercase: Convert variable value to uppercase.nocase: Remove underscores (_) and apply lowercase.remove_: Remove underscores (_).
- Automatic Variable Detection: If no variables JSON file is specified, the application looks for a
variables.jsonfile in the input folder. - Logging Summary: Displays a concise summary with color-coded output, including:
- Number of files found.
- Number of files changed.
- Number of files unchanged.
Installation
Method 1: Install from PyPI
The package is available on PyPI and can be installed directly:
pip install repvar
Method 2: Install from Source
Clone the repository and install the dependencies:
git clone https://github.com/vamanfredi/repvar.git
cd repvar
pip install typer typing-extensions
Method 3: Use uv
Install uv and run the tool installation:
pip install uv
uv tool install --from git+https://github.com/vamanfredi/repvar repvar
Usage
Run the CLI application with the following command:
repvar <input_folder> <output_folder> [variables_json]
Arguments
<input_folder>: Path to the folder containing the files to process.<output_folder>: Path to the folder where processed files will be saved.[variables_json]: Optional. Path to the JSON file with variables. Defaults tovariables.jsonin the input folder.
Example
repvar ./input ./output ./variables.json
Example variables.json
{
"username": "JohnDoe",
"project": "MyProject",
"greeting": "Hello"
}
Result
Before replacement:
- Filename:
welcome_${username}.txt - Content:
Welcome to ${project}, ${greeting}!
After replacement:
- Filename:
welcome_JohnDoe.txt - Content:
Welcome to MyProject, Hello!
Output Example
Upon execution, the CLI will display a summary:
Input Folder: ./input
Output Folder: ./output
Variables Loaded: ['username', 'project', 'greeting']
Files Found: 10
✓ Files Changed: 8
~ Files Unchanged: 2
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file repvar-0.1.221.tar.gz.
File metadata
- Download URL: repvar-0.1.221.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1da6c70c5650b95c87cc634ba55cd61ce0b7421450340c15d4c9d9f5779f75e
|
|
| MD5 |
322f6a7e2214f67bdd293e58ecd86328
|
|
| BLAKE2b-256 |
d555b4977eb7bc42854426d2ede85fb4776d0d9171a64408fedfd1164504ec68
|
Provenance
The following attestation bundles were made for repvar-0.1.221.tar.gz:
Publisher:
python-package.yml on vamanfredi/repvar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
repvar-0.1.221.tar.gz -
Subject digest:
a1da6c70c5650b95c87cc634ba55cd61ce0b7421450340c15d4c9d9f5779f75e - Sigstore transparency entry: 156685982
- Sigstore integration time:
-
Permalink:
vamanfredi/repvar@8197a9102923dd33982d41731ce895d045e89553 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vamanfredi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@8197a9102923dd33982d41731ce895d045e89553 -
Trigger Event:
push
-
Statement type:
File details
Details for the file repvar-0.1.221-py3-none-any.whl.
File metadata
- Download URL: repvar-0.1.221-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87a01c68ef52134e44c115a8af89fd2fd06d81a33867e5ff5d5a27e6424145b0
|
|
| MD5 |
6183945fcad4d269c07fb5c0558ae7ce
|
|
| BLAKE2b-256 |
ef8392b09d2a36807bf512f97b8baf5369bfa646569836925c83195f6b7011b4
|
Provenance
The following attestation bundles were made for repvar-0.1.221-py3-none-any.whl:
Publisher:
python-package.yml on vamanfredi/repvar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
repvar-0.1.221-py3-none-any.whl -
Subject digest:
87a01c68ef52134e44c115a8af89fd2fd06d81a33867e5ff5d5a27e6424145b0 - Sigstore transparency entry: 156685983
- Sigstore integration time:
-
Permalink:
vamanfredi/repvar@8197a9102923dd33982d41731ce895d045e89553 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vamanfredi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@8197a9102923dd33982d41731ce895d045e89553 -
Trigger Event:
push
-
Statement type: