# Command Line Interface
This document covers the `string-pipeline` CLI behavior and supported flags.
## Contents
- [Command Format](#command-format)
- [Template Input](#template-input)
- [Data Input](#data-input)
- [Debug and Validation](#debug-and-validation)
- [Help Commands](#help-commands)
- [Common Patterns](#common-patterns)
- [Exit Behavior](#exit-behavior)
- [Troubleshooting](#troubleshooting)
## Command Format
```bash
string-pipeline [OPTIONS] [TEMPLATE] [INPUT]
```
Arguments:
- `TEMPLATE`: template string
- `INPUT`: input string (optional when using `--validate`; otherwise read from argument, file, or `stdin`)
## Template Input
Choose one template source:
- positional `TEMPLATE`
- `--template-file FILE` (`-t FILE`)
If both are provided, the command fails.
Examples:
```bash
# Inline template
string-pipeline '{upper}' 'hello world'
# Template from file
```
## Data Input
Input source priority:
1. positional `INPUT`
2. `--input-file FILE` (`-f FILE`)
3. `stdin`
If both `input` and `--input-file` are provided, the command fails.
Examples:
```bash
# Positional input
string-pipeline '{upper}' 'hello world'
# Input file
printf 'hello world\n' > input.txt
string-pipeline '{upper}' -f input.txt
# stdin
printf 'hello world\n' | string-pipeline '{upper}'
```
## Debug and Validation
### Debug mode
Enable debug output with:
- inline debug flag: `{!...}`
- CLI flag: `--debug` (`-d`)
Behavior:
- Debug logs go to `stderr`.
- Final result goes to `stdout`.
- `--quiet` (`-q`) suppresses debug logs.
Examples:
```bash
# Inline debug
# CLI debug
# Debug requested, logs suppressed by quiet mode
### Template validation
`--validate` checks template syntax without processing input.
Examples:
```bash
# Validation success
# Quiet validation (no output on success)
## Help Commands
Supported informational flags:
- `--help`, `-h`
- `--version`, `-V`
- `--list-operations`
- `--syntax-help`
Examples:
```bash
string-pipeline --help
string-pipeline --version
string-pipeline --list-operations
string-pipeline --syntax-help
```
## Common Patterns
### Build templates incrementally
```bash
string-pipeline '{split:,:..}' 'a,b,c'
```
### Validate before running
```bash
string-pipeline --template-file normalize.template 'a,b,c'
fi
```
## Exit Behavior
- Exit code `0`: success
- Exit code `1`: parse error, I/O error, validation failure, or runtime processing error
Behavior notes:
- `--validate` does not require input.
- If no template is provided and `stdin` is not available, the CLI prints help.
## Troubleshooting
### Parse errors
- Check missing braces and separators.
- Run `--validate` first.
```bash
### Type errors
- `map` requires list input.
- String-only operations on lists should be inside `map:{...}`.
```bash
# Error: upper on list
# Correct
### Debugging command behavior
```bash
Related documentation:
- `docs/template-system.md`
- `docs/debug-system.md`
- `docs/benchmarking.md`