Created
May 22, 2018 15:56
-
-
Save mattfenwick/5495b38d9f73d9158c9e33214764a95d to your computer and use it in GitHub Desktop.
Add comments to exported functions, methods, types in a golang source tree
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
my $path = $ARGV[0]; | |
# print $path; | |
open(my $file, "<", $path) or die "Unable to open file, $!"; | |
my $contents = do { local $/; <$file> }; | |
close $file; | |
# print $contents; | |
# functions | |
$contents =~ s/(\nfunc\s+)([A-Z][a-zA-Z0-9_]*)/\n\/\/ $2 .....$1$2/sg; | |
# methods | |
$contents =~ s/(\nfunc\s+\([^\)]*\)\s+)([A-Z][a-zA-Z0-9_]*)/\n\/\/ $2 .....$1$2/sg; | |
# types | |
$contents =~ s/(\ntype\s+)([A-Z][a-zA-Z0-9_]*)/\n\/\/ $2 .....$1$2/sg; | |
# print $contents; | |
# print "\n"; | |
open(my $outfile, ">", $path) or die "Unable to open outfile, $!"; | |
print $outfile $contents; |
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
find ./pkg -type f -name "*.go" -exec perl addcomments.pl {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment