cmdparse

A CLI tool that parses unstructured CLI command output into structured formats (JSON, CSV, YAML) with field extraction capabilities.

Features

  • Parse stdin CLI output to JSON/CSV/YAML
  • Auto-detect common output patterns (tables, key-value, delimited)
  • Simple field extraction syntax with dot notation
  • Custom parser definitions via config file
  • Works seamlessly with any Unix pipe

Installation

pip install cmdparse

Or from source:

pip install -e .

Usage

Basic Usage

# Parse table output to JSON
echo -e "NAME    IMAGE    STATUS\nnginx   nginx:1   running" | cmdparse

# Output as YAML
cat file.txt | cmdparse -o yaml

# Output as CSV
cat file.txt | cmdparse -o csv

Field Extraction

# Extract specific fields
echo -e "NAME    IMAGE    STATUS\nnginx   nginx:1   running" | cmdparse -e NAME -e STATUS

# Use dot notation for nested fields

Input Format Detection

# Auto-detect format (default)
cat file.txt | cmdparse

# Force specific format
cat file.txt | cmdparse -f table
cat file.txt | cmdparse -f key_value
cat file.txt | cmdparse -f delimited

Configuration File

# Use custom config file
cat file.txt | cmdparse -c /path/to/config.yaml

Input Formats

cmdparse automatically detects and parses these formats:

Table Format

NAME    IMAGE    STATUS
nginx   nginx:1   running
redis   redis:3   stopped

Key-Value Format (colon)

name: John
age: 30
city: NYC

Key-Value Format (equals)

name=John
age=30
city=NYC

Delimited (CSV)

name,age,city
John,30,NYC
Jane,25,LA

Tab-Delimited (TSV)

name	age	city
John	30	NYC

Output Formats

  • json - JSON output (default)
  • yaml - YAML output
  • csv - CSV output
  • raw - Raw text representation

Configuration

Create a ~/.cmdparse.yaml or .cmdparse.yaml in your project with custom parser definitions:

parsers:
  - name: docker_ps
    pattern: "NAME.*PORTS"
    fields:
      - CONTAINER_ID
      - IMAGE
      - STATUS
      - NAMES

Unix Pipeline Examples

# Parse docker ps output
docker ps | cmdparse -o json

# Extract specific columns from any table-like output
df -h | cmdparse -e Filesystem -e Size -e Use%

# Parse key-value config output
env | cmdparse -f key_value -o yaml

# Process CSV data
cat data.csv | cmdparse -o json

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest -v

# Run with coverage
pytest --cov=cmdparse

License

MIT License

Description
A CLI tool that parses unstructured CLI command output into structured formats (JSON, CSV, YAML) with field extraction capabilities.
Readme 91 KiB
v0.1.0 Latest
2026-02-04 02:09:09 +00:00
Languages
Python 100%