aboutsummaryrefslogtreecommitdiffstats
path: root/readme_generator.pl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--readme_generator.pl61
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;
+}