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.
- 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.
The package is available on PyPI and can be installed directly:
pip install repvarClone the repository and install the dependencies:
git clone https://github.com/vamanfredi/repvar.git
cd repvar
pip install typer typing-extensionsInstall uv and run the tool installation:
pip install uv
uv tool install --from git+https://github.com/vamanfredi/repvar repvarRun the CLI application with the following command:
repvar <input_folder> <output_folder> [variables_json]<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.
repvar ./input ./output ./variables.json{
"username": "JohnDoe",
"project": "MyProject",
"greeting": "Hello"
}Before replacement:
- Filename:
welcome_${username}.txt - Content:
Welcome to ${project}, ${greeting}!
After replacement:
- Filename:
welcome_JohnDoe.txt - Content:
Welcome to MyProject, Hello!
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
This project is licensed under the MIT License. See the LICENSE file for details.