A bash script that counts go function and method lines of code (including whitespace and comments)
#!/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