Created
June 12, 2020 14:09
-
-
Save timruffles/eec75d0784245283fe52dfe419d21eb5 to your computer and use it in GitHub Desktop.
A bash script that counts go function and method lines of code (including whitespace and comments)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Usage: bash count_functions_loc.sh some/directory | |
set -euo pipefail | |
main() { | |
for f in $(find $1 -name '*.go' -not -name 'test_*.go'); do | |
count_funcs < "$f" | awk "{ print \"$f\", \$1, \$2 }" | |
done | |
} | |
count_funcs() { | |
ruby -e 'STDIN.read.scan(/(^func\s*(?:\([^)]+\))?\s*(\w+)\(.+?^})/m) {|whole, name| puts("#{name}\t#{whole.scan(/\n/).length}")}; nil' | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment