From 7aef3df21c1b899126fa908b8fc6d7f7cc7f4018 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 21:53:09 +0000 Subject: [PATCH] Initial upload: README, CI workflow, gitignore --- README.md | 324 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 167 insertions(+), 157 deletions(-) diff --git a/README.md b/README.md index 5bf3cdd..3fbff84 100644 --- a/README.md +++ b/README.md @@ -1,90 +1,66 @@ -# ConfigConverter CLI +# Config Converter CLI -A CLI tool for real-time bidirectional conversion and validation between JSON, YAML, and TOML formats with JMESPath query support. +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) +[![Gitea Actions](https://7000pct.gitea.bloupla.net/7000pctAUTO/config-converter-cli/actions/workflows/ci.yml/badge.svg)](https://7000pct.gitea.bloupla.net/7000pctAUTO/config-converter-cli/actions) + +A powerful CLI tool for converting configuration files between JSON, YAML, TOML, and INI formats with schema inference, validation, TypeScript interface generation, and colorized output. ## Features -- **Bidirectional Format Conversion**: Convert between JSON, YAML, and TOML formats -- **Syntax Validation**: Validate configuration files with colored error output -- **Pretty-Printing**: Format output with configurable indentation levels (2, 4, 8 spaces) -- **JMESPath Query Support**: Filter and extract data using JMESPath queries -- **Stdin/Stdout Pipeline Support**: Read from stdin and write to stdout for pipeline integration -- **Batch File Processing**: Process multiple files in batch mode +- **Multi-format Conversion**: Convert between JSON, YAML, TOML, and INI formats +- **Schema Inference**: Automatically infer schemas from configuration files +- **Validation**: Validate configuration files against inferred schemas +- **TypeScript Generation**: Generate TypeScript interfaces from configurations +- **Batch Processing**: Convert multiple files using glob patterns +- **Colorized Output**: Beautiful colored output using Rich library +- **Interactive Mode**: Guided conversion workflow ## Installation +### From Source + +```bash +# Clone the repository +git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/config-converter-cli.git +cd config-converter-cli + +# Install dependencies +pip install -e . + +# Or install with dev dependencies +pip install -e ".[dev]" +``` + +### From PyPI + ```bash pip install config-converter-cli ``` -Or install from source: +## Usage -```bash -git clone -cd config-converter-cli -pip install -e . -``` +### Basic Conversion -## Quick Start - -### Convert a file +Convert a single file from one format to another: ```bash # Convert JSON to YAML -config-converter convert config.json --to yaml -o config.yaml +config-converter convert config.json -t yaml -o config.yaml # Convert YAML to TOML -config-converter convert config.yaml --to toml +config-converter convert settings.yaml -t toml -o settings.toml -# Convert with custom indentation -config-converter convert config.json --to yaml --indent 4 +# Auto-detect format from extension +config-converter convert app.json --to yaml -o app.yaml ``` -### Validate a file +### Supported Formats -```bash -# Validate a JSON file -config-converter validate config.json - -# Validate with format hint -config-converter validate config.cfg --format yaml - -# Quiet mode (only exit code) -config-converter validate --quiet config.json -``` - -### Query data - -```bash -# Query a specific key -config-converter query config.json "server.host" - -# Query nested values -config-converter query config.yaml "database.settings.port" - -# Use JMESPath expressions -config-converter query config.json "services[?enabled==`true`].name" -``` - -### Format/pretty-print - -```bash -# Format with 4-space indentation -config-converter format config.json --indent 4 - -# Convert and format -config-converter format config.yaml --to json -``` - -### Batch processing - -```bash -# Convert multiple files -config-converter batch *.json --to yaml - -# Convert to output directory -config-converter batch config1.yaml config2.yaml --to toml --output-dir converted/ -``` +- **JSON** (`.json`) +- **YAML** (`.yaml`, `.yml`) +- **TOML** (`.toml`) +- **INI** (`.ini`, `.cfg`) ## Commands @@ -93,136 +69,170 @@ config-converter batch config1.yaml config2.yaml --to toml --output-dir converte Convert a configuration file from one format to another. ```bash -config-converter convert [OPTIONS] [INPUT_FILE] -``` +config-converter convert SOURCE -t FORMAT [-o OUTPUT] [-f FORMAT] [-w] Options: -- `--from, -f FORMAT`: Input format (auto-detected if not specified) -- `--to, -t FORMAT`: Output format (required) -- `--indent, -i LEVEL`: Indentation level (2, 4, or 8) -- `--output, -o FILE`: Output file -- `--validate/--no-validate`: Validate input before conversion - -### validate - -Validate the syntax of a configuration file. - -```bash -config-converter validate [OPTIONS] [INPUT_FILE] + -t, --to FORMAT Target format (required) + -o, --output FILE Output file path + -f, --from FORMAT Source format (auto-detected if not specified) + -w, --overwrite Overwrite output file if it exists ``` -Options: -- `--format, -F FORMAT`: Format hint (auto-detected if not specified) -- `--quiet, -q`: Only return exit code, no output - -### query - -Query configuration data using JMESPath. - -```bash -config-converter query [OPTIONS] [INPUT_FILE] EXPRESSION -``` - -Options: -- `--format, -F FORMAT`: Format hint (auto-detected if not specified) -- `--output, -o FORMAT`: Output format (json or text) - -### format - -Format/pretty-print a configuration file. - -```bash -config-converter format [OPTIONS] [INPUT_FILE] -``` - -Options: -- `--indent, -i LEVEL`: Indentation level (2, 4, or 8) -- `--to, -t FORMAT`: Output format -- `--compact, -c`: Use compact output - ### batch -Convert multiple files in batch mode. +Convert multiple files matching a glob pattern. ```bash -config-converter batch [OPTIONS] INPUT_FILES... -``` +config-converter batch "*.json" -t yaml -o ./output/ Options: -- `--from, -f FORMAT`: Input format (auto-detected if not specified) -- `--to, -t FORMAT`: Output format (required) -- `--indent, -i LEVEL`: Indentation level (2, 4, or 8) -- `--output-dir, -o DIR`: Output directory for converted files + -t, --to FORMAT Target format (required) + -o, --output-dir DIR Output directory + -f, --from FORMAT Source format (auto-detected if not specified) + -w, --overwrite Overwrite output files if they exist +``` -## Pipeline Support +### infer -All commands support stdin/stdout with `-`: +Infer and display the schema of a configuration file. ```bash -# Read from stdin -cat config.json | config-converter convert --to yaml +config-converter infer config.json [-f FORMAT] [-t] [-t] -# Write to stdout -config-converter convert config.json --to yaml > config.yaml +Options: + -f, --format FORMAT Input format (auto-detected if not specified) + -t, --table Display as table + --tree Display as tree structure +``` -# Chained pipelines -cat config.json | config-converter query "server" | config-converter format --indent 4 +Example output: +```json +{ + "root_type": "object", + "properties": [ + {"name": "name", "type": "string", "required": true}, + {"name": "version", "type": "string", "required": true}, + {"name": "port", "type": "integer", "required": true} + ] +} +``` + +### validate + +Validate a configuration file against its inferred schema. + +```bash +config-converter validate config.json [-f FORMAT] +``` + +### generate-ts + +Generate TypeScript interfaces from a configuration file. + +```bash +config-converter generate-ts config.json [-f FORMAT] [-i NAME] [-o FILE] + +Options: + -i, --interface NAME Interface name (default: "Config") + -o, --output FILE Output file path +``` + +Example output: +```typescript +export interface Config { + name: string; + version: string; + port: number; + database: { + host: string; + port: number; + }; +} +``` + +### interactive + +Enter interactive mode for guided conversion. + +```bash +config-converter interactive +``` + +### formats + +List all supported formats. + +```bash +config-converter formats ``` ## Examples -### CI/CD Pipeline Integration +### Convert configuration with nested structures -```bash -# Validate configuration in CI -config-converter validate --quiet config/$ENV/config.json || exit 1 - -# Convert and deploy -config-converter convert config/$ENV/app.json --to yaml | kubectl apply -f - +```json +// config.json +{ + "app": { + "name": "myapp", + "version": "1.0.0" + }, + "database": { + "host": "localhost", + "port": 5432, + "ssl": true + } +} ``` -### Configuration Transformation - ```bash -# Extract specific settings -config-converter query config.json "database.settings" > db_settings.json - -# Reformat with consistent indentation -config-converter format config.yaml --indent 4 --to json > config_formatted.json +config-converter convert config.json -t yaml -o config.yaml ``` -### JMESPath Queries +```yaml +# config.yaml +app: + name: myapp + version: 1.0.0 +database: + host: localhost + port: 5432 + ssl: true +``` + +### Batch conversion ```bash -# Get all enabled services -config-converter query config.json "services[?enabled==`true`].name" +# Convert all JSON config files to YAML +config-converter batch "configs/*.json" -t yaml -o configs/yaml/ +``` -# Get nested values -config-converter query config.yaml "server.tls.cert_path" +### Generate TypeScript interfaces -# Transform output -config-converter query config.json "{host: server.host, port: server.port}" +```bash +config-converter generate-ts app.config.json -i AppConfig -o app.config.ts ``` ## Configuration -No configuration file required. All options are passed via command-line arguments. +### Environment Variables -## Error Handling +- `NO_COLOR`: Set to disable colorized output -The tool provides detailed error messages with: -- Line and column numbers for syntax errors -- Colored output for better visibility -- Context snippets around error locations +## Development -## Contributing +### Running Tests -1. Fork the repository -2. Create a feature branch -3. Make your changes -4. Run tests: `pytest -v` -5. Submit a pull request +```bash +pytest tests/ -v +``` + +### Installing Dev Dependencies + +```bash +pip install -e ".[dev]" +``` ## License -MIT License \ No newline at end of file +MIT