| name | Using CLIs Effectively |
| description | Best practices and patterns for discovering, using, and integrating with command-line interfaces |
Using CLIs Effectively
Skill Overview
This skill teaches you how to effectively discover, use, and integrate with command-line interfaces (CLIs), with particular focus on custom Python CLIs and tool wrappers.
Discovery Process
1. Start with Help
Always begin with --help:
<cli> --help
<cli> <subcommand> --help
<cli> -h
Example:
python3 snippets_cli.py --help
python3 snippets_cli.py update --help
2. Explore the Source
For Python CLIs, read the argparse setup:
find ~/.claude -name "*cli.py" | grep snippets
grep -A 50 "argparse" <cli_file>
grep -A 20 "add_argument" <cli_file>
Look for:
- Subcommands (create, update, delete, list)
- Required vs optional arguments
- Flag types (store_true, choices, etc.)
- Default values
3. List Current State
Before modifying anything, understand what exists:
<cli> list
<cli> get <name>
<cli> config show
Safe Usage Patterns
1. Dry Run First
Test commands without making changes:
<cli> update <item> --dry-run
<cli> delete <item> --dry-run --verbose
2. Use Verbose Mode
See what's happening:
<cli> update <item> --verbose
<cli> update <item> -v
<cli> update <item> --debug
3. Create Backups
Before destructive operations:
<cli> delete <item> --backup
<cli> update <item> --backup-dir ~/backups
cp config.json config.json.backup
4. Validate Before Execute
Use get/show commands to verify:
<cli> get <name>
<cli> update <name> --pattern "new-pattern" --dry-run
<cli> update <name> --pattern "new-pattern"
<cli> get <name>
Common CLI Patterns
CRUD Operations
Most CLIs follow CRUD patterns:
<cli> create <name> --pattern "..." --file content.md
<cli> list
<cli> get <name>
<cli> update <name> --pattern "new-pattern"
<cli> update <name> --file new-content.md
<cli> delete <name>
<cli> delete <name> --force
Configuration Management
Multiple config files:
<cli> update <name> --pattern "..."
<cli> update <name> --pattern "..." --config work
<cli> update <name> --pattern "..." --base
Output Formats
Get machine-readable output:
<cli> list --json
<cli> get <name> --json
<cli> list --json | jq '.[] | select(.enabled == true)'
<cli> list --format tsv
Integration Patterns
1. Scripting CLIs
Write scripts that use CLIs:
#!/bin/bash
set -e
update_snippet() {
local name="$1"
local pattern="$2"
if ! snippets_cli.py get "$name" >/dev/null 2>&1; then
echo "Error: Snippet '$name' not found"
return 1
fi
snippets_cli.py update "$name" \
--pattern "$pattern" \
--backup
echo "Updated $name"
}
update_snippet "download-pdf" "\\bDOWNLOAD\\b[.:;,]?"
2. Error Handling
Check exit codes:
if <cli> update <name> --pattern "..."; then
echo "Success"
else
echo "Failed with exit code $?"
exit 1
fi
3. Parsing Output
Extract information from CLI output:
pattern=$(<cli> get <name> --json | jq -r '.pattern')
<cli> get <name> | grep "pattern:" | cut -d'"' -f2
Real Example: Snippets CLI
Discovery
find ~/.claude -name "snippets_cli.py"
python3 snippets_cli.py --help
python3 snippets_cli.py update --help
python3 snippets_cli.py list | head -20
Safe Update Workflow
cd ~/.claude/plugins/marketplaces/warren-claude-code-plugin-marketplace/claude-context-orchestrator/scripts
python3 snippets_cli.py get download-pdf
python3 snippets_cli.py update download-pdf \
--pattern "\\bDOWNLOAD\\b[.:;,]?"
python3 snippets_cli.py get download-pdf | grep pattern
python3 snippets_cli.py list | grep -A 5 "download-pdf"
Update Pattern and Content
python3 snippets_cli.py update download-pdf \
--pattern "\\bDOWNLOAD\\b[.:;,]?" \
--file ~/new-content.md
python3 snippets_cli.py get other-snippet --json | \
jq -r '.content' | \
python3 snippets_cli.py update download-pdf --content -
Advanced Patterns
Batch Operations
Update multiple items:
for snippet in mail gcal post; do
python3 snippets_cli.py update "$snippet" --enabled true
done
echo "mail gcal post" | xargs -n1 python3 snippets_cli.py get
Programmatic Usage
Use CLIs from Python:
import subprocess
import json
def get_snippet(name):
"""Get snippet details via CLI"""
result = subprocess.run(
['python3', 'snippets_cli.py', 'get', name, '--json'],
capture_output=True,
text=True
)
if result.returncode == 0:
return json.loads(result.stdout)
return None
def update_pattern(name, pattern):
"""Update snippet pattern via CLI"""
result = subprocess.run(
['python3', 'snippets_cli.py', 'update', name,
'--pattern', pattern],
capture_output=True,
text=True
)
return result.returncode == 0
Testing CLI Changes
Before committing changes:
cp config.local.json config.local.json.backup
python3 snippets_cli.py update <name> --pattern "..."
cp config.local.json.backup config.local.json
git add config.local.json
git commit -m "Update: Changed <name> pattern"
Troubleshooting
CLI Not Found
find ~/.claude -name "*cli.py"
find ~/Desktop -name "*cli.py"
which <cli-command>
python3 /full/path/to/cli.py
Permission Denied
chmod +x <cli-file>
python3 <cli-file>
Invalid Arguments
<cli> <subcommand> --help
grep "add_argument.*dry" <cli-file>
Config File Issues
cat config.local.json | python3 -m json.tool
ls -la config*.json
ls -la config.local.json
Best Practices Summary
- Always check
--help first
- Read the source for Python CLIs (argparse section)
- List before modifying (understand current state)
- Use dry-run when available
- Enable verbose mode for debugging
- Create backups before destructive operations
- Validate after changes (get/show commands)
- Check exit codes in scripts
- Use JSON output for programmatic use
- Document your CLI usage (scripts, examples)
Related Skills
- MANAGESKILL - Managing and creating Agent Skills
- TDD - Test-driven development for CLI tools
- DEEPSEARCH - Finding CLIs and their documentation
Quick Reference Card
<cli> --help
<cli> <cmd> --help
grep -r "argparse" <cli-dir>
<cli> get <name>
<cli> update <name> --dry-run
<cli> delete <name> --backup
<cli> list
<cli> create <name> [opts]
<cli> update <name> [opts]
<cli> delete <name>
<cli> list --json
<cli> get <name> --verbose
<cli> cmd --config work
<cli> cmd --base
<cli> cmd