A simple, lightweight CLI tool to transform a cloc
output into a Markdown
table written in Go
.
- A
unix
-like operating system (with eitherbash
orsh
, etc.); - The
cloc
command-line utility; - The
wget
command-line utility.
*The wget
command-line utility is used to download the clocrt
binary. Indeed, clocrt
is not a fork of cloc
, and therefore, cloc
is a direct dependency of clocrt
.
A copy of the Go
binary is needed to install the clocrt
binary from the source. The Go
binary is available here.
The automated installation is carried with a single command:
$ curl -s https://raw.githubusercontent.com/michalspano/clocrt/main/install | sh
$ git clone https://github.com/michalspano/clocrt.git && cd clocrt
$ go build -o clocrt src/main.go
$ ./clocrt --version # validates the installation
Suppose the following working tree with some dummy files:
$ tree ./test
test
├── docs
│ └── foo.md
├── foo.go
└── foo.py
Running cloc
would yield the following output:
$ cloc ./test
3 text files.
3 unique files.
0 files ignored.
github.com/AlDanial/cloc v 1.94 T=0.00 s (626.3 files/s, 1878.9 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Go 1 2 0 5
Markdown 1 0 0 1
Python 1 0 0 1
-------------------------------------------------------------------------------
SUM: 3 2 0 7
-------------------------------------------------------------------------------
Which we transform into a Markdown
table with clocrt
:
$ clocrt "`cloc ./test`"
Language | files | blank | comment | code |
---|---|---|---|---|
Go | 1 | 2 | 0 | 5 |
Markdown | 1 | 0 | 0 | 1 |
Python | 1 | 0 | 0 | 1 |
SUM: | 3 | 2 | 0 | 7 |
*Markdown
table syntax: link
Voila! 🎊
$ clocrt -h
$ clocrt --help
NAME
clocrt - count lines of code redefined tables
DESCRIPTION
A simple, lightweight CLI tool to transform a cloc output into a Markdown table.
USAGE
clocrt "`[CLOC-PATTERN]`" [OPTIONS]
OPTIONS
--help, -h show the usage
--version, -v fetch and display the current version
--print, -pr print the result to stdout
--cell-align|-ca=<align> center|c (default), left|l, right|r
--output-path|-op=<path> output file path (default: out.md)
BUGS
Don't forget to quote the pattern per the example: "`[CLOC-PATTERN]`"
Documentation of the cloc
command-line utility can be found here.
I'm open to any contribution to the repository. If you have any suggestions or feedback, please open an issue or pull request. 👍
With the respect to the MIT
License provided within the project: link.