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
- Clone the repository:
git clone https://github.com/vamanfredi/repvar.git cd repvar
- Install dependencies:
pip install typer typing-extensions
Method 2: Use uv
- Install uv:
pip install uv
- Run uv tool install:
uv tool install --from git+https://github.com/vamanfredi/repvar repvar
Usage
Run the CLI application with the following command:
python main.py replace <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
python main.py replace ./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}!
- Filename:
- After replacement:
- Filename:
welcome_JohnDoe.txt - Content:
Welcome to MyProject, Hello!
- Filename:
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.22.tar.gz.
File metadata
- Download URL: repvar-0.1.22.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7c0ba9665860932fb9f0fe852fea9ac03c814f0905dc09fd860444f2ab935eb
|
|
| MD5 |
faf03e56ca87ab08cae38672d4789374
|
|
| BLAKE2b-256 |
d3c675a36b7055c0fa11aef27af7ca3590eeba3a425641355bcd0f149aa1bb1f
|
File details
Details for the file repvar-0.1.22-py3-none-any.whl.
File metadata
- Download URL: repvar-0.1.22-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66ad3950549198612f036838f1f362b2947ed5686f0c3a77b21ec0f78ef91af0
|
|
| MD5 |
bffb33c689f205a6df3cf4d2894fd386
|
|
| BLAKE2b-256 |
17f4a4f5bbe0935562ce84f31df21b08c81644c08c353cd845ebca5728b2abb5
|