A collection of focused, single-purpose Python command-line tools designed for UNIX pipeline compatibility.
- Single Responsibility: Each tool does ONE specific task well
- Pipeline Compatible: Tools work seamlessly in UNIX pipelines
- Consistent Interface: Standard argument patterns across all tools
- Quiet Mode: Support for silent operation with exit codes only
- Full Paths: Always preserve and display full file paths
Every tool follows this basic structure:
#!/usr/bin/env python3
"""
Tool Name - Brief description
"""
import argparse
import sys
from typing import Optional, List
def process_files(files: List[str], quiet: bool = False) -> bool:
"""Process files and return success status."""
# Tool-specific logic here
pass
def main():
parser = argparse.ArgumentParser(description="Tool description")
parser.add_argument('-q', '--quiet', action='store_true', help='Quiet mode')
parser.add_argument('-a', '--algorithm', help='Algorithm to use')
parser.add_argument('files', nargs='+', help='Files to process')
args = parser.parse_args()
success = process_files(args.files, args.quiet)
if args.quiet:
sys.exit(0 if success else 1)
# Output in 'filename: score' format
for filename, score in results:
print(f"{filename}: {score}")
if __name__ == "__main__":
main()
- Use
argparse
for argument parsing - Support
-q/--quiet
for silent operation - Support
-a
as shortcut for--algorithm
- Accept file arguments (positional or via
-f/--files
) - Provide
-h/--help
and--version
- Default:
filename: score
- JSON:
{"filename": "path", "score": value}
- CSV:
filename,score
- Quiet: No output, exit code only
0
: Success1
: General error2
: Invalid input3
: File not found4
: Permission error
- Always use
.venv/bin/python
interpreter - Use type hints throughout
- Follow PEP 8 style guidelines
- Include comprehensive docstrings
tools/
├── core/ # Shared utilities
├── config/ # Configuration files
├── templates/ # Tool templates
├── tests/ # Test files
├── tool1/ # Individual tool directories
├── tool2/
└── README.md
-
Create New Tool:
mkdir new-tool cp templates/tool_template.py new-tool/main.py chmod +x new-tool/main.py
-
Run Tool:
.venv/bin/python tool/main.py [args]
-
Test Pipeline Compatibility:
find . -name "*.txt" | .venv/bin/python tool/main.py
# Process single file
.venv/bin/python tool/main.py file.txt
# Process multiple files
.venv/bin/python tool/main.py file1.txt file2.txt
# Quiet mode
.venv/bin/python tool/main.py -q file.txt
# Pipeline usage
find . -name "*.txt" | .venv/bin/python tool/main.py
# Standard output
/path/to/file.txt: 0.85
/another/path/file.txt: 0.72
# JSON output
{"filename": "/path/to/file.txt", "score": 0.85}
# Quiet mode (no output, exit code only)
echo $? # 0 for success, 1 for failure
When adding new tools:
- Follow the established paradigm
- Use the template structure
- Include comprehensive tests
- Document any deviations from standard patterns
- Ensure pipeline compatibility
- Test quiet mode functionality