- 1. Purpose
- 2. Command syntax
- 3. Commands
- 4. Layer 1: Preprocessing options
- 5. Layer 2: Algorithm options
- 6. Layer 3: Match options
- 7. Layer 4: Diff formatting options
- 8. Format specification options
- 9. General options
- 10. Environment variables
- 11. Complete examples
- 12. Configuration patterns
- 13. Exit codes
- 14. See also
1. Purpose
This page provides a complete reference for all Canon command-line interface options organized by command and function.
For conceptual understanding, see Comparison Pipeline.
For choosing the right configuration, see Choosing Configuration.
3. Commands
3.1. format command
Format a document using canonicalization rules.
canon format FILE [OPTIONS]
Options:
| Option | Description |
|---|---|
|
Specify format: xml, html, json, yaml |
|
Write output to file (default: stdout) |
|
Apply preprocessing: none, c14n, normalize, format |
4. Layer 1: Preprocessing options
Controls document normalization before comparison.
| Option | Description |
|---|---|
|
Preprocessing mode: |
Modes:
* none - No preprocessing (compare as-is)
* c14n - Canonicalize (XML C14N, JSON/YAML sorted keys)
* normalize - Normalize whitespace throughout
* format - Pretty-print with standard formatting
See Preprocessing for details.
5. Layer 2: Algorithm options
Controls which comparison algorithm to use.
| Option | Description |
|---|---|
|
Algorithm: |
Algorithms:
* dom - Fast, stable, positional comparison
* semantic - Slower, intelligent, detects moves
See Algorithms for details.
6. Layer 3: Match options
Controls what to compare and how strictly.
6.1. Match profiles
| Option | Description |
|---|---|
|
Profile: |
Profiles:
* strict - Exact matching (all dimensions strict)
* rendered - Browser rendering (ignores formatting)
* spec_friendly - Test-friendly (most common)
* content_only - Maximum tolerance
6.2. Match dimensions
Individual dimension control (overrides profile settings):
| Option | Description |
|---|---|
|
Text content: |
|
Structural whitespace: |
|
Attribute whitespace (XML/HTML): |
|
Attribute order (XML/HTML): |
|
Attribute values (XML/HTML): |
|
Key order (JSON/YAML): |
|
Comments: |
|
Whitespace type sensitivity: |
See Match Options for details.
7. Layer 4: Diff formatting options
Controls how differences are displayed.
7.1. Diff mode
| Option | Description |
|---|---|
|
Mode: |
Modes:
* by_line - Traditional line-by-line diff
* by_object - Tree-based semantic diff
7.2. Display options
| Option | Description |
|---|---|
|
Show configuration tables and detailed information (diffs always shown when files differ) |
|
Enable/disable colored output (default: enabled) |
|
Lines of context around changes (default: 3) |
|
Group changes within N lines (default: nil) |
|
Display legend for symbols (default: true with verbose) |
|
Filter displayed differences: |
See Diff Formatting for details.
8. Format specification options
| Option | Description |
|---|---|
|
Format for both files: |
|
Format of first file (overrides --format) |
|
Format of second file (overrides --format) |
9. General options
| Option | Description |
|---|---|
|
Show help message |
|
Show version |
|
Enable debug output |
10. Environment variables
| Variable | Description |
|---|---|
|
Set to |
|
Set to disable colored output (overrides --color) |
11. Complete examples
11.1. Example 1: Basic comparison
canon diff file1.xml file2.xml --verbose
Uses all defaults: * Layer 1: No preprocessing * Layer 2: DOM algorithm * Layer 3: Format defaults (XML strict matching) * Layer 4: by_object mode with colors
11.2. Example 2: Test-friendly comparison
canon diff expected.xml actual.xml \
--match-profile spec_friendly \
--verbose
Uses: * Layer 1: Normalize preprocessing (from profile) * Layer 2: DOM algorithm (default) * Layer 3: spec_friendly profile * Layer 4: by_object mode with colors
11.3. Example 3: Semantic analysis
canon diff old.xml new.xml \
--diff-algorithm semantic \
--match-profile spec_friendly \
--diff-mode by_object \
--verbose
Uses: * Layer 1: Normalize preprocessing * Layer 2: Semantic algorithm (detects moves) * Layer 3: spec_friendly matching * Layer 4: by_object mode (shows operations)
11.4. Example 4: Exact matching with context
canon diff file1.json file2.json \
--match-profile strict \
--diff-mode by_line \
--context-lines 5 \
--verbose
Uses: * Layer 1: No preprocessing * Layer 2: DOM algorithm * Layer 3: strict profile (exact matching) * Layer 4: by_line mode with 5 context lines
11.5. Example 5: Custom dimension control
canon diff page1.html page2.html \
--preprocessing normalize \
--text-content normalize \
--structural-whitespace ignore \
--attribute-order ignore \
--comments ignore \
--diff-mode by_line \
--verbose
Uses: * Layer 1: Normalize preprocessing * Layer 2: DOM algorithm * Layer 3: Custom dimensions * Layer 4: by_line mode
12. Configuration patterns
12.1. Fast comparison (default)
canon diff file1.xml file2.xml
-
Minimal processing
-
Fast DOM algorithm
-
Format defaults
-
No verbose output
12.2. Test scenario
canon diff expected.xml actual.xml \
--match-profile spec_friendly \
--verbose
-
Ignores formatting
-
Shows actionable diffs
-
Most common for testing
13. Exit codes
| Code | Meaning |
|---|---|
|
Documents are equivalent |
|
Documents differ |
|
Error occurred (invalid arguments, file not found, etc.) |
14. See also
-
Comparison Pipeline - 4-layer architecture
-
Choosing Configuration - Decision guide
-
Match Options - Dimension reference
-
Diff Formatting - Output customization
-
CLI Interface - Command-line usage guide
-
Ruby API - Programmatic usage