Source Code Merger is a command line tool that merges multiple source files from a project directory into a single file. Useful for coding competitions like codingame or any situation where you must submit a single source file.
Per-language adapters control how files are bundled. The Go adapter:
- picks up every
*.gofile in the source directory (*_test.goignored), - promotes
main.goto the top of the output, - emits a single
packageclause and a single dedupedimport (...)block, - strips all comments (line, inline, block, doc).
cgmerge [-s <source_dir>] [-o <output_file>] [-l <lang>]If --lang is omitted, the language is auto-detected from a marker file in the source directory (e.g. main.go for Go).
If --output ends with the placeholder .ext, it is replaced by the adapter's real extension (so the default bundle.ext becomes bundle.go).
-s, --source string Source directory to parse (default ".")
-o, --output string Output file name (default "bundle.ext")
-l, --lang string Source language (auto-detect if empty)
-h, --help Show usage summary
-v, --version Show versionAuto-detect language, write ./bundle.go next to the sources:
cgmerge -s ./example/golangForce the Go adapter, write to a custom path:
cgmerge -s ./cmd/bit -l go -o ./tmp/bit-bundle.go
# merged ./cmd/bit -> ./tmp/bit-bundle.go (10234 bytes)Use the .ext placeholder so the adapter picks the extension:
cgmerge -s ./example/golang -o ./tmp/bundle.ext
# merged ./example/golang -> ./tmp/bundle.go (1421 bytes)MIT © 2023 Dmitrii Barsukov