summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--draco.19
-rwxr-xr-xdraco.pl9
2 files changed, 14 insertions, 4 deletions
diff --git a/draco.1 b/draco.1
index c08be26..d68912b 100644
--- a/draco.1
+++ b/draco.1
@@ -6,7 +6,7 @@
.Nd a script to convert reddit thread to Org document
.Sh SYNOPSIS
.Nm draco
-.Op -v
+.Op Fl dv
.Ar <url>
.Sh DESCRIPTION
.Nm
@@ -15,6 +15,13 @@ is a script to convert reddit thread to Org document. It accepts a url
It'll also print comments along with their replies. It's limited by
the reddit API.
+
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl d
+Turn on debug messages. Debug messages will be printed to STDERR.
+.It Fl v
+Print version.
.Pp
.Sh NOTES
Draco will add 2 spaces before every new line. Comments/Posts may
diff --git a/draco.pl b/draco.pl
index 37e4654..ac67ee9 100755
--- a/draco.pl
+++ b/draco.pl
@@ -15,13 +15,14 @@ my $lb = Unicode::LineBreak->new(ColMax => 76); # Default is 76.
# Printing UTF-8 to STDOUT.
binmode(STDOUT, "encoding(UTF-8)");
-my $VERSION = "v0.1.2";
-
-die "usage: draco [-v] <url>\n" unless scalar @ARGV;
+die "usage: draco [-dv] <url>\n" unless scalar @ARGV;
+my $DEBUG;
+my $VERSION = "v0.1.3";
# Dispatch table to be parsed before url.
my %dispatch = (
'-v' => sub { print "Draco $VERSION\n"; exit; },
+ '-d' => sub { $DEBUG = 1; print STDERR "draco: debug on.\n"; },
);
if (exists $dispatch{$ARGV[0]}) {
# shift @ARGV to get $url in next shift.
@@ -35,11 +36,13 @@ my $json_url = "${url}.json";
my $http = HTTP::Tiny->new( verify_SSL => 1 );
# Fetch the post.
+print STDERR "draco: fetching `$json_url'.\n" if $DEBUG;
my $response = $http->get($json_url);
die "Unexpected response - $response->{status}: $response->{reason}"
unless $response->{success};
# Decode json.
+print STDERR "draco: decoding json response.\n" if $DEBUG;
my $json_data = decode_json($response->{content});
# $post contains post data