Initial upload: README, CI workflow, gitignore
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
324
README.md
324
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.
|
[](https://opensource.org/licenses/MIT)
|
||||||
|
[](https://www.python.org/downloads/)
|
||||||
|
[](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
|
## Features
|
||||||
|
|
||||||
- **Bidirectional Format Conversion**: Convert between JSON, YAML, and TOML formats
|
- **Multi-format Conversion**: Convert between JSON, YAML, TOML, and INI formats
|
||||||
- **Syntax Validation**: Validate configuration files with colored error output
|
- **Schema Inference**: Automatically infer schemas from configuration files
|
||||||
- **Pretty-Printing**: Format output with configurable indentation levels (2, 4, 8 spaces)
|
- **Validation**: Validate configuration files against inferred schemas
|
||||||
- **JMESPath Query Support**: Filter and extract data using JMESPath queries
|
- **TypeScript Generation**: Generate TypeScript interfaces from configurations
|
||||||
- **Stdin/Stdout Pipeline Support**: Read from stdin and write to stdout for pipeline integration
|
- **Batch Processing**: Convert multiple files using glob patterns
|
||||||
- **Batch File Processing**: Process multiple files in batch mode
|
- **Colorized Output**: Beautiful colored output using Rich library
|
||||||
|
- **Interactive Mode**: Guided conversion workflow
|
||||||
|
|
||||||
## Installation
|
## 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
|
```bash
|
||||||
pip install config-converter-cli
|
pip install config-converter-cli
|
||||||
```
|
```
|
||||||
|
|
||||||
Or install from source:
|
## Usage
|
||||||
|
|
||||||
```bash
|
### Basic Conversion
|
||||||
git clone <repository>
|
|
||||||
cd config-converter-cli
|
|
||||||
pip install -e .
|
|
||||||
```
|
|
||||||
|
|
||||||
## Quick Start
|
Convert a single file from one format to another:
|
||||||
|
|
||||||
### Convert a file
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Convert JSON to YAML
|
# 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
|
# 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
|
# Auto-detect format from extension
|
||||||
config-converter convert config.json --to yaml --indent 4
|
config-converter convert app.json --to yaml -o app.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Validate a file
|
### Supported Formats
|
||||||
|
|
||||||
```bash
|
- **JSON** (`.json`)
|
||||||
# Validate a JSON file
|
- **YAML** (`.yaml`, `.yml`)
|
||||||
config-converter validate config.json
|
- **TOML** (`.toml`)
|
||||||
|
- **INI** (`.ini`, `.cfg`)
|
||||||
# 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/
|
|
||||||
```
|
|
||||||
|
|
||||||
## Commands
|
## 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.
|
Convert a configuration file from one format to another.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
config-converter convert [OPTIONS] [INPUT_FILE]
|
config-converter convert SOURCE -t FORMAT [-o OUTPUT] [-f FORMAT] [-w]
|
||||||
```
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
- `--from, -f FORMAT`: Input format (auto-detected if not specified)
|
-t, --to FORMAT Target format (required)
|
||||||
- `--to, -t FORMAT`: Output format (required)
|
-o, --output FILE Output file path
|
||||||
- `--indent, -i LEVEL`: Indentation level (2, 4, or 8)
|
-f, --from FORMAT Source format (auto-detected if not specified)
|
||||||
- `--output, -o FILE`: Output file
|
-w, --overwrite Overwrite output file if it exists
|
||||||
- `--validate/--no-validate`: Validate input before conversion
|
|
||||||
|
|
||||||
### validate
|
|
||||||
|
|
||||||
Validate the syntax of a configuration file.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
config-converter validate [OPTIONS] [INPUT_FILE]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
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
|
### batch
|
||||||
|
|
||||||
Convert multiple files in batch mode.
|
Convert multiple files matching a glob pattern.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
config-converter batch [OPTIONS] INPUT_FILES...
|
config-converter batch "*.json" -t yaml -o ./output/
|
||||||
```
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
- `--from, -f FORMAT`: Input format (auto-detected if not specified)
|
-t, --to FORMAT Target format (required)
|
||||||
- `--to, -t FORMAT`: Output format (required)
|
-o, --output-dir DIR Output directory
|
||||||
- `--indent, -i LEVEL`: Indentation level (2, 4, or 8)
|
-f, --from FORMAT Source format (auto-detected if not specified)
|
||||||
- `--output-dir, -o DIR`: Output directory for converted files
|
-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
|
```bash
|
||||||
# Read from stdin
|
config-converter infer config.json [-f FORMAT] [-t] [-t]
|
||||||
cat config.json | config-converter convert --to yaml
|
|
||||||
|
|
||||||
# Write to stdout
|
Options:
|
||||||
config-converter convert config.json --to yaml > config.yaml
|
-f, --format FORMAT Input format (auto-detected if not specified)
|
||||||
|
-t, --table Display as table
|
||||||
|
--tree Display as tree structure
|
||||||
|
```
|
||||||
|
|
||||||
# Chained pipelines
|
Example output:
|
||||||
cat config.json | config-converter query "server" | config-converter format --indent 4
|
```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
|
## Examples
|
||||||
|
|
||||||
### CI/CD Pipeline Integration
|
### Convert configuration with nested structures
|
||||||
|
|
||||||
```bash
|
```json
|
||||||
# Validate configuration in CI
|
// config.json
|
||||||
config-converter validate --quiet config/$ENV/config.json || exit 1
|
{
|
||||||
|
"app": {
|
||||||
# Convert and deploy
|
"name": "myapp",
|
||||||
config-converter convert config/$ENV/app.json --to yaml | kubectl apply -f -
|
"version": "1.0.0"
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5432,
|
||||||
|
"ssl": true
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuration Transformation
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Extract specific settings
|
config-converter convert config.json -t yaml -o config.yaml
|
||||||
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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### JMESPath Queries
|
```yaml
|
||||||
|
# config.yaml
|
||||||
|
app:
|
||||||
|
name: myapp
|
||||||
|
version: 1.0.0
|
||||||
|
database:
|
||||||
|
host: localhost
|
||||||
|
port: 5432
|
||||||
|
ssl: true
|
||||||
|
```
|
||||||
|
|
||||||
|
### Batch conversion
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Get all enabled services
|
# Convert all JSON config files to YAML
|
||||||
config-converter query config.json "services[?enabled==`true`].name"
|
config-converter batch "configs/*.json" -t yaml -o configs/yaml/
|
||||||
|
```
|
||||||
|
|
||||||
# Get nested values
|
### Generate TypeScript interfaces
|
||||||
config-converter query config.yaml "server.tls.cert_path"
|
|
||||||
|
|
||||||
# Transform output
|
```bash
|
||||||
config-converter query config.json "{host: server.host, port: server.port}"
|
config-converter generate-ts app.config.json -i AppConfig -o app.config.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## 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:
|
## Development
|
||||||
- Line and column numbers for syntax errors
|
|
||||||
- Colored output for better visibility
|
|
||||||
- Context snippets around error locations
|
|
||||||
|
|
||||||
## Contributing
|
### Running Tests
|
||||||
|
|
||||||
1. Fork the repository
|
```bash
|
||||||
2. Create a feature branch
|
pytest tests/ -v
|
||||||
3. Make your changes
|
```
|
||||||
4. Run tests: `pytest -v`
|
|
||||||
5. Submit a pull request
|
### Installing Dev Dependencies
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT License
|
MIT
|
||||||
|
|||||||
Reference in New Issue
Block a user