Skip to content

CLI Commands

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.

These flags are available for all commands:

FlagShortDescriptionDefault
--help-hShow help for command
--version-vShow version information
--config-cPath to configuration file.similarity-go.yaml
--verboseEnable verbose outputfalse
--quiet-qSuppress non-essential outputfalse

Analyze Go code for similarities.

Terminal window
./bin/similarity-go [flags] [paths...]
  • paths...: One or more paths to analyze (files or directories)
FlagTypeDescriptionDefault
--threshold, -tfloatSimilarity threshold (0.0-1.0)0.8
--format, -fstringOutput format (json, yaml)text
--workers, -wintNumber of parallel workersCPU cores
--cacheboolEnable caching for improved performancefalse
--verbose, -vboolEnable verbose loggingfalse
Terminal window
# 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 ./

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

For building from source:

  • Go 1.24.5+
  • golangci-lint (for development)

Display version information:

Terminal window
./bin/similarity-go --version

similarity-go uses standard exit codes:

CodeMeaning
0Success - No high similarities found
1High similarities detected
2Error in execution

Shows similarity results with highlighted matches and similarity scores.

Structured output suitable for integration with other tools:

Terminal window
./bin/similarity-go --format json ./src

YAML structured output:

Terminal window
./bin/similarity-go --format yaml ./src