From 56e880f5028d9f1892d1af28007ab6a7108ad977 Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 20 Nov 2020 10:21:58 +0530 Subject: Add debug option, bump version to v0.1.3 --- draco.1 | 9 ++++++++- draco.pl | 9 ++++++--- 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 .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] \n" unless scalar @ARGV; +die "usage: draco [-dv] \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 -- cgit 1.4.1-2-gfad0