Skip to main content

Validate CLI and Python projects

Project description

mustmatch

Assert CLI output. Test your documentation.

# Verify command output
echo "hello" | mustmatch "hello"

# Test for substrings
ls -la | mustmatch like "README"

# JSON comparison (field order doesn't matter)
echo '{"status":"ok","count":42}' | mustmatch like '{"status":"ok"}'

# Regex patterns
date +%Y-%m-%d | mustmatch '/^\d{4}-\d{2}-\d{2}$/'

# Assert errors DON'T appear
echo "success" | mustmatch not like "error"

Install

pip install mustmatch

Why mustmatch?

Your documentation has examples. But do they work?

# This example in your README:
echo "hello" | mustmatch "hello"

# Will it work tomorrow? Next week? After refactoring?
# With mustmatch, your docs are tests. If docs pass, examples work.

Quick Start

1. Pipe and Match

echo "hello" | mustmatch "hello"        # ✓ Exit 0
echo "hello world" | mustmatch like "world"   # ✓ Contains
echo "success" | mustmatch not like "error"   # ✓ Negation

2. Auto-Detection

mustmatch figures out what you want:

# String comparison
echo "hello" | mustmatch "hello"

# Regex (from /slashes/)
date +%Y-%m-%d | mustmatch '/^\d{4}-\d{2}-\d{2}$/'

# JSON (from {braces})
echo '{"a":1,"b":2}' | mustmatch '{"a":1,"b":2}'

3. JSON Intelligence

# Field order doesn't matter
echo '{"b":2,"a":1}' | mustmatch '{"a":1,"b":2}'

# Subset matching
echo '{"status":"ok","count":42}' | mustmatch like '{"status":"ok"}'

Comparison Modes

Exact Match

echo "hello" | mustmatch "hello"

Contains (like)

echo "hello world" | mustmatch like "world"
ls -la | mustmatch like "README"

Negation (not)

echo "success" | mustmatch not "error"
echo "success" | mustmatch not like "error"

Regex (/pattern/)

date +%Y-%m-%d | mustmatch '/^\d{4}-\d{2}-\d{2}$/'
echo "v1.2.3" | mustmatch '/^v\d+\.\d+\.\d+$/'

JSON (semantic)

# Field order doesn't matter
echo '{"b":2,"a":1}' | mustmatch '{"a":1,"b":2}'

# Subset matching
echo '{"status":"ok","count":42,"time":"2024-01-01"}' | \
    mustmatch like '{"status":"ok"}'

Text Normalization

mustmatch automatically cleans output:

# ANSI codes stripped
ls --color=always | mustmatch like "README"

# Whitespace trimmed
echo "  hello  " | mustmatch "hello"

# Newlines normalized
printf "hello\r\n" | mustmatch "hello"

Exit Codes

echo "ok" | mustmatch "ok"              # Exit 0 (match)
echo "ok" | mustmatch "fail" || echo "no match"   # Exit 1

# Use in scripts
if echo "ready" | mustmatch "ready"; then
    echo "Proceeding..."
fi

Use Cases

Keep Documentation Up-to-Date

Every example in your docs becomes a test. If the example breaks, CI fails.

DevOps Scripts

Verify service health in deployment scripts.

API Testing

Test JSON API responses with semantic comparison.

CLI Reference

Usage:
    command | mustmatch [not] [like] EXPECTED

Options:
    -i, --ignore-case    Case-insensitive
    -q, --quiet          Suppress output
    --version            Show version
    -h, --help           Show help

Exit codes:
    0    Match succeeded
    1    Match failed
    2    Invalid arguments

Examples

# Exact match
echo "hello" | mustmatch "hello"

# Case insensitive
echo "HELLO" | mustmatch -i "hello"

# Contains
echo "hello world" | mustmatch like "world"

# Negation
echo "success" | mustmatch not like "error"

# Regex
date +%Y-%m-%d | mustmatch '/^\d{4}-\d{2}-\d{2}$/'

# JSON
echo '{"a":1,"b":2}' | mustmatch '{"a":1,"b":2}'

# JSON subset
echo '{"status":"ok","count":42}' | mustmatch like '{"status":"ok"}'

# Check help output
mustmatch --help | mustmatch like "Usage:"

# Verify version
mustmatch --version | mustmatch like "mustmatch"

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mustmatch-0.0.1.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mustmatch-0.0.1-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file mustmatch-0.0.1.tar.gz.

File metadata

  • Download URL: mustmatch-0.0.1.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for mustmatch-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b9760f89f9507d382f1893739e211dc0d3bef6a49125f1539a68bf92a4a2043a
MD5 f34b6702e589d3afdfa61b5eb66a3384
BLAKE2b-256 e36d7f1e87e1b6a8c3f519a4c6da89d41cf1c99db6281d63c2c62fe577ad212b

See more details on using hashes here.

File details

Details for the file mustmatch-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mustmatch-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for mustmatch-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 195cef552196fca58d2a63ce45d8b356a8a10b8ae62f305874cc6db77a1c56eb
MD5 c884387f22a911ae78a1b2eb8e9ad204
BLAKE2b-256 f49679e69b23f2e67347dc1bf57020028250a4769e9a19dfbcc78376b487e6a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page