ConfigForge
A powerful CLI tool for converting between configuration formats (JSON, YAML, TOML, ENV, INI) with built-in validation, schema inference, and TypeScript interface generation.
Features
- Format Conversion: Convert seamlessly between JSON, YAML, TOML, ENV, and INI formats
- Schema Validation: Validate configurations against JSON Schema specifications
- TypeScript Generation: Generate TypeScript interfaces from configurations
- Batch Processing: Convert multiple files with glob pattern support
- Syntax Highlighting: Colorized output for better readability
- Schema Inference: Automatically infer JSON Schema from configurations
Installation
From Source
cargo install --path .
Pre-built Binaries
Download pre-built binaries from the releases page.
Quick Start
Convert a file
config-forge convert -i config.json -t yaml
config-forge convert -i config.yaml -t toml -o config.toml
Validate against schema
config-forge validate -c config.json -s schema.json
config-forge validate -c config.yaml -S schema.yaml --schema-format file
Generate TypeScript interfaces
config-forge generate-ts -i config.json -o config.ts
config-forge generate-ts -i config.json --interface-name AppConfig
Batch conversion
config-forge batch -p "configs/**/*.json" -t yaml
config-forge batch -p "*.toml" -t json -o ./json_output
Infer schema from config
config-forge infer -i config.json -o schema.json
Usage
Convert Command
Convert between configuration formats.
config-forge convert -i <input> [-f <from_format>] -t <to_format> [-o <output>] [--no-highlight]
Options:
-i, --input: Input file path (required)-f, --from: Input format (auto-detected if not specified)-t, --to: Output format (required)-o, --output: Output file path (stdout if not specified)--no-highlight: Disable syntax highlighting
Supported formats: json, yaml, toml, env, ini
Validate Command
Validate configuration against a JSON Schema.
config-forge validate -c <config> [-s <schema> | -S <schema-file>] [--schema-format <format>]
Options:
-c, --config: Configuration file to validate (required)-s, --schema: Inline JSON Schema-S, --schema-file: Path to schema file--schema-format: Schema format (inlineorfile)
Generate-TS Command
Generate TypeScript interfaces from configurations.
config-forge generate-ts -i <input> [-f <from_format>] [-o <output>] [-n <name>] [--export]
Options:
-i, --input: Input file path (required)-f, --from: Input format (auto-detected if not specified)-o, --output: Output file path (stdout if not specified)-n, --interface-name: Interface name (default: filename)--export: Add export keyword
Batch Command
Convert multiple files using glob patterns.
config-forge batch -p <pattern> -t <format> [-o <output_dir>] [--parallel] [--no-highlight]
Options:
-p, --pattern: Glob pattern for input files (required)-t, --to: Output format (required)-o, --output-dir: Output directory (default: current directory)--parallel: Process files in parallel--no-highlight: Disable syntax highlighting
Infer Command
Infer JSON Schema from a configuration file.
config-forge infer -i <input> [-f <from_format>] [-o <output>]
Options:
-i, --input: Input file path (required)-f, --from: Input format (auto-detected if not specified)-o, --output: Output file path (stdout if not specified)
Init Command
Create a default configuration file.
config-forge init [-o <output>]
Options:
-o, --output: Output file path (default:configforge.toml)
Global Options
--no-color: Disable color output-v, --verbose: Enable verbose output--help: Show help information--version: Show version information
Configuration
ConfigForge can be configured using a configforge.toml file in your project directory:
output_dir = "./"
default_format = "json"
color_output = true
parallel_processing = false
Environment variables:
CONFIG_FORGE_NO_COLOR: Disable color outputCONFIG_FORGE_VERBOSE: Enable verbose output
Examples
Convert JSON to YAML
config-forge convert -i app.json -t yaml
Convert with custom output
config-forge convert -i config.toml -t json -o config.json
Validate with inline schema
config-forge validate -c app.json -s '{"type": "object", "properties": {"name": {"type": "string"}}}'
Generate TypeScript with custom name
config-forge generate-ts -i config.json -n AppConfig -o app.ts
Batch convert with parallel processing
config-forge batch -p "**/*.toml" -t json --parallel
Infer and save schema
config-forge infer -i config.yaml -o schema.json
Building
cargo build
cargo build --release
Testing
cargo test
cargo test --all
cargo clippy
cargo fmt --check
Error Handling
| Error | Message | Solution |
|---|---|---|
| UnsupportedFormat | Unsupported format 'xyz' | Check format spelling |
| FileNotFound | File 'path' not found | Verify file exists |
| ParseError | Failed to parse format | Check file syntax |
| ValidationError | Validation failed at path | Review schema requirements |
| SchemaParseError | Invalid JSON Schema | Verify schema syntax |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.