Skip to main content

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.json file 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 to variables.json in 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repvar-0.1.220.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repvar-0.1.220-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file repvar-0.1.220.tar.gz.

File metadata

  • Download URL: repvar-0.1.220.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for repvar-0.1.220.tar.gz
Algorithm Hash digest
SHA256 92d6bfa360f3840232baf8495ff0ddd426c8dba071508287109420456ecfbf63
MD5 4d3e3bb52221c02f14fe389ec362e146
BLAKE2b-256 55e32d8b8373430b1a3545c56a75b915b6998c8c84a8ac86e2a6e41973a8eb24

See more details on using hashes here.

File details

Details for the file repvar-0.1.220-py3-none-any.whl.

File metadata

  • Download URL: repvar-0.1.220-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

Hashes for repvar-0.1.220-py3-none-any.whl
Algorithm Hash digest
SHA256 e69d7b2bd6f8cea88285eed1abe5281089e6555b08146d0422c1536b1af56ceb
MD5 54401644b8f286b151d9d19f046c03d8
BLAKE2b-256 5c47c8128b01b9c9f9f0147a1f49c1dd39aec4520bf572499b227126a6d25ac3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page