diff options
author | Tom Feist <shabble@metavore.org> | 2011-04-18 07:01:35 +0000 |
---|---|---|
committer | Tom Feist <shabble@metavore.org> | 2011-04-18 07:01:35 +0000 |
commit | ccba436af54ff690c3853bf015e43767a356a7d6 (patch) | |
tree | d9ca16659238a6f7a06bd7357e3a636d5f0c5ba9 | |
parent | converted comments to POD. I hope it's worth it. (diff) | |
download | irssi-scripts-ccba436af54ff690c3853bf015e43767a356a7d6.tar.gz irssi-scripts-ccba436af54ff690c3853bf015e43767a356a7d6.zip |
readme_generator: script to generate README.md files for github to use.
Diffstat (limited to '')
-rw-r--r-- | readme_generator.pl | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/readme_generator.pl b/readme_generator.pl new file mode 100644 index 0000000..20e7312 --- /dev/null +++ b/readme_generator.pl @@ -0,0 +1,61 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# Goal: extract the comments from the top of each script file, and +# turn them into some sort of markdown-style README.md for github to nom on. +# +# Not sure how it's going to work with multiple files in a dir though. Sections? + + +use File::Find; +use File::Spec; +use Pod::Markdown; + +my @dirs = @ARGV // '.'; + +find(\&wanted, @dirs); + +sub wanted { + my ($file, $dir, $path) = ($_, $File::Find::dir, $File::Find::name); + return unless $file =~ m/\.pl$/; + + _err("processing file: $path"); +} + +sub read_input_file { + my ($path, $filename) = @_; + + my $filepath = File::Spec->catfile($path, $filename); + + open my $rfh, '<', $filepath or die "Couldn't open $filepath for output: $!"; + + _err("reading $filepath"); + + my $parser = Pod::Markdown->new; + + $parser->parse($rfh); + + close $rfh; + + create_output_file($path, 'README.md', $parser); +} + +sub create_output_file { + my ($path, $filename, $parser) = @_; + + my $filepath = File::Spec->catfile($path, $filename); + + _err("Writing to $filepath"); + + open my $wfh, '>', $filepath or die "Couldn't open $filepath for output: $!"; + print $wfh $parser->as_markdown; + close $wfh; +} + +sub _err { + my ($msg, @args) = @_; + my $str = sprintf($msg, @args); + print STDERR $str; +} |