195 lines
3.5 KiB
Markdown
195 lines
3.5 KiB
Markdown
# Data Format Converter CLI Tool
|
|
|
|
A CLI tool that converts between JSON, YAML, TOML, and CSV formats with validation, syntax highlighting, and an interactive TUI mode.
|
|
|
|
## Features
|
|
|
|
- Multi-format conversion (JSON, YAML, TOML, CSV)
|
|
- Syntax validation with detailed error reporting
|
|
- Syntax highlighting using Rich library
|
|
- Interactive TUI mode for data viewing and editing
|
|
- File watching for live conversions
|
|
- Stdin/stdout support for piping
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install data-format-converter
|
|
```
|
|
|
|
Or from source:
|
|
|
|
```bash
|
|
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/data-format-converter.git
|
|
cd data-format-converter
|
|
pip install -e .
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
Convert a JSON file to YAML:
|
|
```bash
|
|
dfc convert input.json -to yaml -o output.yaml
|
|
```
|
|
|
|
Convert CSV to JSON:
|
|
```bash
|
|
dfc convert data.csv -to json -o data.json
|
|
```
|
|
|
|
Validate a file:
|
|
```bash
|
|
dfc validate config.yaml
|
|
```
|
|
|
|
Interactive mode:
|
|
```bash
|
|
dfc tui config.json
|
|
```
|
|
|
|
Watch file for changes:
|
|
```bash
|
|
dfc watch input.yaml -to json -o output/
|
|
```
|
|
|
|
## Usage
|
|
|
|
```
|
|
Usage: dfc [OPTIONS] COMMAND [ARGS]...
|
|
```
|
|
|
|
### Commands
|
|
|
|
- **convert**: Convert between data formats
|
|
- **validate**: Validate syntax of data files
|
|
- **tui**: Launch interactive TUI mode
|
|
- **watch**: Watch files for changes and auto-convert
|
|
- **info**: Show information about supported formats
|
|
|
|
### Options
|
|
|
|
- `--help`: Show help message
|
|
- `--theme`: Set syntax highlighting theme (default, monokai, github-dark, github-light, dracula, nord, one-dark)
|
|
|
|
## Examples
|
|
|
|
### Basic Conversion
|
|
|
|
```bash
|
|
# JSON to YAML
|
|
dfc convert config.json -to yaml -o config.yaml
|
|
|
|
# YAML to TOML
|
|
dfc convert settings.yaml -to toml -o settings.toml
|
|
|
|
# CSV to JSON
|
|
dfc convert data.csv -to json -o data.json
|
|
|
|
# JSON to CSV
|
|
dfc convert data.json -to csv -o data.csv
|
|
```
|
|
|
|
### Piping
|
|
|
|
```bash
|
|
# Read from stdin, write to stdout
|
|
cat config.json | dfc convert -f json -to yaml
|
|
|
|
# Use - for stdin/stdout
|
|
dfc convert input.yaml -to json - < input.yaml
|
|
```
|
|
|
|
### Validation
|
|
|
|
```bash
|
|
# Validate a single file
|
|
dfc validate config.json
|
|
|
|
# Validate with detailed output
|
|
dfc validate --verbose config.yaml
|
|
|
|
# Validate from stdin
|
|
dfc validate --stdin --format json < config.json
|
|
```
|
|
|
|
### Interactive Mode
|
|
|
|
```bash
|
|
# Open file in interactive viewer
|
|
dfc tui config.json
|
|
|
|
# Open with custom theme
|
|
dfc tui config.json --theme monokai
|
|
```
|
|
|
|
### File Watching
|
|
|
|
```bash
|
|
# Watch a single file
|
|
dfc watch input.json -to yaml -o output/
|
|
|
|
# Watch multiple files (glob pattern)
|
|
dfc watch "*.json" -to yaml -o output/
|
|
```
|
|
|
|
## File Formats
|
|
|
|
| Format | Extension | Read | Write |
|
|
|--------|-------------|------|-------|
|
|
| JSON | .json | ✓ | ✓ |
|
|
| YAML | .yaml, .yml | ✓ | ✓ |
|
|
| TOML | .toml | ✓ | ✓ |
|
|
| CSV | .csv | ✓ | ✓ |
|
|
|
|
## Interactive Mode Controls
|
|
|
|
- **Arrow keys**: Navigate
|
|
- **edit <path> <value>**: Edit a value
|
|
- **add <path> <value>**: Add a new key
|
|
- **delete <path>**: Delete a key
|
|
- **show**: Show current data
|
|
- **save**: Save changes
|
|
- **quit**: Exit without saving
|
|
- **help**: Show help
|
|
|
|
## Configuration
|
|
|
|
Create a `config.toml` file in your home directory or specify with `--config`:
|
|
|
|
```toml
|
|
[default]
|
|
output_dir = "./output"
|
|
theme = "github-dark"
|
|
|
|
[convert]
|
|
indent = 2
|
|
|
|
[validate]
|
|
strict = false
|
|
```
|
|
|
|
## Development
|
|
|
|
```bash
|
|
# Install in development mode
|
|
pip install -e ".[dev]"
|
|
|
|
# Run tests
|
|
pytest tests/ -v
|
|
|
|
# Run linter
|
|
ruff check .
|
|
```
|
|
|
|
## Contributing
|
|
|
|
1. Fork the repository
|
|
2. Create a feature branch
|
|
3. Make your changes
|
|
4. Run tests: `pytest tests/ -v`
|
|
5. Submit a pull request
|
|
|
|
## License
|
|
|
|
MIT License
|