CLI Commands
Overview
Section titled “Overview”similarity-go is a high-performance CLI tool that uses multi-factor AST analysis to detect code similarity in Go projects. The main command analyzes files and directories with configurable options.
Global Flags
Section titled “Global Flags”These flags are available for all commands:
| Flag | Short | Description | Default |
|---|---|---|---|
--help | -h | Show help for command | |
--version | -v | Show version information | |
--config | -c | Path to configuration file | .similarity-go.yaml |
--verbose | Enable verbose output | false | |
--quiet | -q | Suppress non-essential output | false |
Main Command
Section titled “Main Command”Analyze Go code for similarities.
./bin/similarity-go [flags] [paths...]Arguments
Section titled “Arguments”paths...: One or more paths to analyze (files or directories)
| Flag | Type | Description | Default |
|---|---|---|---|
--threshold, -t | float | Similarity threshold (0.0-1.0) | 0.8 |
--format, -f | string | Output format (json, yaml) | text |
--workers, -w | int | Number of parallel workers | CPU cores |
--cache | bool | Enable caching for improved performance | false |
--verbose, -v | bool | Enable verbose logging | false |
Examples
Section titled “Examples”# Basic analysis of current directory./bin/similarity-go ./
# Analyze specific directories with custom threshold./bin/similarity-go --threshold 0.9 ./cmd ./internal
# Export results to JSON./bin/similarity-go --format json ./ > results.json
# Use custom number of workers with verbose output./bin/similarity-go --workers 4 --verbose ./src
# Enable caching for large projects./bin/similarity-go --cache --threshold 0.85 ./Algorithm Details
Section titled “Algorithm Details”The similarity detection uses multi-factor analysis:
- AST Tree Edit Distance: Measures structural differences between code
- Token Sequence Analysis: Compares token patterns and sequences
- Structural Signatures: Creates fingerprints of code structure
- Weighted Scoring: Combines multiple metrics for accurate similarity scoring
Development Requirements
Section titled “Development Requirements”For building from source:
- Go 1.24.5+
- golangci-lint (for development)
Version Information
Section titled “Version Information”Display version information:
./bin/similarity-go --versionExit Codes
Section titled “Exit Codes”similarity-go uses standard exit codes:
| Code | Meaning |
|---|---|
0 | Success - No high similarities found |
1 | High similarities detected |
2 | Error in execution |
Output Formats
Section titled “Output Formats”Default (Human-readable)
Section titled “Default (Human-readable)”Shows similarity results with highlighted matches and similarity scores.
JSON Format
Section titled “JSON Format”Structured output suitable for integration with other tools:
./bin/similarity-go --format json ./srcYAML Format
Section titled “YAML Format”YAML structured output:
./bin/similarity-go --format yaml ./src